作者:乔山办公网日期:
返回目录:excel表格制作
vbs读取excel脚本倒是好说,但你的程序明显在vb与vba之间,恕我看7a64e4b893e5b19e362不懂。 给你个例子参考下:
' Read an Excel Spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
("C:\Scripts\New_users.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).Value
Wscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).Value
Wscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).Value
Wscript.Echo "LastName: " & objExcel.Cells(intRow, 4).Value
intRow = intRow + 1
Loop
objExcel.Quit
ALT+F11打开百VBA编辑器,度粘贴以知下道代码回,F5运行。答
Sub test()
Dim k, m As Integer
Dim str, str1, str2 As String
Sheet1.Activate
k = Range("g65535").End(xlUp).Row
m = 1
For i = 2 To k
str1 = Cells(i, 7).Value
str2 = Cells(i + 1, 7).Value
If str1 = str2 Then
m = m + 1
Else
str = str & str1 & " " & m & Chr(10)
m = 1
End If
Next
MsgBox str
End Sub
set xlapp=getobject(,"excel.application")
set xlbook=xlapp.workbooks("工作抄簿1")
set xlsheet=xlbook.sheets("sheet1")
msgbox xlsheet.range("a1")'''读取数据
xlsheet.range("a1")=10000''''写数袭据
xlbook.save'''未保存过百用saveas 路径 这是度保存
xlbook.close true ''关闭问工作簿1
xlapp.quit '''退出答excel
Set oexcel=CreateObject("excel.application")
Set obook=oexcel.Workbooks.Open("c:\test\excel.xls")
Set osheet=obook.Sheets("sheet1")
'显示第一zd个工作表版A1单元格数权据
msgbox osheet.cells(1,1)
Set obook=Nothing
Set osheet=Nothing
oexcel.Quit