怎么在VBS中遍歷Excel工作表-創(chuàng)新互聯(lián)

這篇文章給大家介紹怎么在VBS中遍歷Excel工作表,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供成都網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。

核心代碼

'******************************************
'拖拽文件,獲取文件路徑
'******************************************
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遍歷所有工作簿中所有工作表執(zhí)行宏

Sub test()
n = Worksheets.Count
For i = 1 To n
Worksheets(i).Activate
Macro1
Next
End Sub

 Macro1是宏的名稱

 使用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文件內(nèi)容到數(shù)組并提示輸出

解壓到任意目錄,點擊VBS文件執(zhí)行,程序自動讀取文件所在目錄的Excel文件到數(shù)組中,并通過提示框逐個輸出,提示框1s自動關(guān)閉。

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 '關(guān)閉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

關(guān)于怎么在VBS中遍歷Excel工作表就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

名稱欄目:怎么在VBS中遍歷Excel工作表-創(chuàng)新互聯(lián)
新聞來源:http://muchs.cn/article26/dpchjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、企業(yè)網(wǎng)站制作、商城網(wǎng)站、響應(yīng)式網(wǎng)站、虛擬主機微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)