Èí¼þ¿ª·¢Åàѵ°à >> ±à³Ì¿ª·¢ >> VbScript
VBSé��历Excel工作表的实现代ç � |
|
¡¡¡¡±¾ÎıêÇ©£ºVBSé��历Excel æ ¸å¿ƒä»£ç �
'******************************************
'拖拽文件,获�文件路�
'******************************************
If wscript.Arguments.count=0 then
msgbox "æ‹–æ‹½æ–‡ä»¶åˆ°æœ¬å›¾æ ‡",0,"æ��示"
End if
for a=0 to wscript.Arguments.count-1
strPath=wscript.Arguments(a)
next
'******************************************
'定义Excle对象�工作薄对象�工作表对象
'******************************************
dim oExcel,oWb,oSheet
set ws=WScript.createobject("wscript.shell")
Set oExcel=CreateObject("Excel.Application")
'打开指定的工作簿
Set oWb=oExcel.Workbooks.Open(strPath)
'显示打开的Excel工作�
oExcel.visible=true
'******************************************
'�历工作簿的所有工作表
'******************************************
for j= 1 to oWb.sheets.count
set oSheet=oWb.Sheets(j)
'选ä¸å¹¶æ¿€æ´»å·¥ä½œè¡¨
oSheet.Activate
oSheet.Range("A1")="�功"
next
Excelé��åŽ†æ‰€æœ‰å·¥ä½œç°¿ä¸æ‰€æœ‰å·¥ä½œè¡¨æ‰§è¡Œå®?/strong> Sub test() n = Worksheets.Count For i = 1 To n Worksheets(i).Activate Macro1 Next End Sub Macro1是å®�çš„å��ç§?/p> 使用VBSé��历EXCEL
Dim xlApp,xlSheet,xlWorkBookDim iRowCount,iLoop,jLoop,jColumnCount,numAdd
Set xlApp=CreateObject("Excel.Application")
xlApp.Visible=True
Set xlWorkBook=xlApp.Workbooks.Open("C:data.xls")
Set xlSheet=xlWorkBook.Sheets("Sheet1")
iRowCount=xlSheet.UsedRange.Rows.Count
jColumnCount=xlSheet.UsedRange.Columns.Count
For iLoop=1 To iRowCount
For jLoop=1 To jColumnCount
MsgBox(xlSheet.cells(iLoop,jLoop).value)
Next
Next
xlWorkBook.Save
xlWorkBook.Close
xlApp.Quit
VBScript 编写 自动Excel文件内容到数组并æ��示输出 解压到任æ„�目录,点击VBS文件执行,程åº�自动读å�–文件所在目录的Excel文件到数组ä¸ï¼Œå¹¶é€šè¿‡æ��示框é€�个输出,æ��示框1s自动关é—ã€?/p>
Dim oExcel,oWb,oSheet
Set oExcel= CreateObject("Excel.Application")
Set oWb = oExcel.Workbooks.Open(dir&"DataReport.xls")
Set oSheet = oWb.Sheets("HistoryData")
Dim i
Dim a(150)
For i = 5 To 145 '145-5+1 = 141
a(i-5) = oSheet.Range("B"&i).Value
print "data=",a(i-5)
next
Set oSheet = Nothing
oExcel.Workbooks.Close
oExcel.Quit 'å…³é—excel.exe'
Function Dir()
Set WshShell = CreateObject("Wscript.Shell")
Dir = WshShell.CurrentDirectory
End Function
Function print (prompt,title)
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Popup prompt &title,1,""
End Function
为了方便å¦ä¹ 特将代ç �打包æ��供下载 下载地å�€ |