乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>vbs</em> <em>获取excel</em>某列中每个相同

<em>vbs</em> <em>获取excel</em>某列中每个相同

作者:乔山办公网日期:

返回目录: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

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网