最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

VBS遍歷Excel工作表的實(shí)現(xiàn)代碼

 更新時(shí)間:2019年12月08日 17:50:45   投稿:mdxy-dxy  
這篇文章主要介紹了VBS遍歷Excel工作表的實(shí)現(xiàn)代碼,需要的朋友可以參考下

核心代碼

'******************************************
'拖拽文件,獲取文件路徑
'******************************************
If wscript.Arguments.count=0 then 
		msgbox "拖拽文件到本圖標(biāo)",0,"提示"
End if 
 
 
for a=0 to wscript.Arguments.count-1
 
	strPath=wscript.Arguments(a)	
	
next
'******************************************
'定義Excle對(duì)象、工作薄對(duì)象、工作表對(duì)象
'******************************************
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 編寫 自動(dòng)Excel文件內(nèi)容到數(shù)組并提示輸出

解壓到任意目錄,點(diǎn)擊VBS文件執(zhí)行,程序自動(dòng)讀取文件所在目錄的Excel文件到數(shù)組中,并通過提示框逐個(gè)輸出,提示框1s自動(dòng)關(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

為了方便學(xué)習(xí)特將代碼打包提供下載 下載地址

相關(guān)文章

最新評(píng)論

江孜县| 新建县| 甘谷县| 武汉市| 三台县| 洞头县| 卢龙县| 秦安县| 威远县| 亳州市| 娱乐| 张掖市| 璧山县| 嘉荫县| 陇南市| 丹江口市| 都江堰市| 二连浩特市| 拉萨市| 福建省| 怀柔区| 古田县| 桂阳县| 新巴尔虎左旗| 柳江县| 莫力| 漳州市| 南投县| 滁州市| 郸城县| 崇信县| 基隆市| 永和县| 慈溪市| 华容县| 赫章县| 芦山县| 罗平县| 出国| 延边| 南宫市|