通过vbscript批量更新excel文档oracle数据源(版本1:connection.refresh方法)

<pre><span style="font-family:Microsoft YaHei;"></span><address><span style="font-family:KaiTi_GB2312;font-size:12px;color:#ff0000;">*************************************************</span></address><address><span style="font-family:KaiTi_GB2312;font-size:12px;"><span style="font-size:12px;color:#ff0000;">** 原文: blog.csdn.net/clark_xu <span style="font-family:KaiTi_GB2312;font-size:12px;color:#ff0000;">徐长亮的专栏</span></span></span></address><address><span style="font-family:KaiTi_GB2312;font-size:12px;"></span><span style="color:#ff0000;"><span style="font-family:KaiTi_GB2312;"><span style="font-size:12px;">** 微信公众号:clark_blog      </span></span></span></address><address><span style="font-family:KaiTi_GB2312;font-size:12px;color:#ff0000;">*************************************************</span></address>
'wsript对象
dim xlsWorkBook	'workbook对象
dim xlsSheet		'worksheet对象
dim xlscon			'connection对象
dim xlsquery		'querytable对象
dim i						'connection基数
dim j						'内部循环

dim fileapp 'wscript文件对象
dim folderdir
dim folderobject
dim subfolderobject
dim filename
dim subdirpath

'wscriptExcel 对象
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
xlsApp.DisplayAlerts=False

'wscript 文件系统对象
Set fileapp=CreateObject("Scripting.FileSystemObject")

'文件根目录
'folderdir=InputBox("文件夹路径,例如E:\15-VB", MsgTitle)
folderdir="E:\15-VB"

'folder对象,Subfolder对象
Set folderobject=fileapp.GetFolder(folderdir)
Set subfolderobject=folderobject.SubFolders

for each i in folderobject.files
 			if i.type="Microsoft Office Excel 97-2003 工作表"  or i.type="Microsoft Office Excel 工作表" then
 			  filename=folderdir&"\"&i.name
 			  msgbox filename 
        '创建workbooks对象
				set xlsWorkBook=xlsApp.Workbooks.open(filename)
				'for next循环
				for j=1 to xlsWorkBook.connections.count
				    set xlscon=xlsWorkBook.connections(j)
				    'msgbox xlscon
						xlscon.refresh
						On Error Resume Next 
			  next
			  msgbox xlsApp.StatusBar
				msgbox xlsApp.DisplayStatusBar
				sleep 30000
			  xlsWorkBook.Save		
 			end if
next

'子目录递归处理
for each subdirpath in subfolderobject
 			for each i in subdirpath.files
 				if i.type="Microsoft Office Excel 97-2003 工作表"  or i.type="Microsoft Office Excel 工作表" then
 			  	filename=subdirpath&"\"&i.name
 			  	msgbox filename
 			  	'创建workbooks对象
					set xlsWorkBook=xlsApp.Workbooks.open(filename)
					'for next循环
					for j=1 to xlsWorkBook.connections.count
				    set xlscon=xlsWorkBook.connections(j)
				    'msgbox xlscon
						xlscon.refresh
						On Error Resume Next 
			 	 	next
			  	msgbox xlsApp.StatusBar
					msgbox xlsApp.DisplayStatusBar
					sleep 30000
			  	xlsWorkBook.Save	
 				end if
			next 
next
				
 '退出操作
'xlsWorkBook.Close
xlsApp.Quit

Set xlscon=Nothing '释放内存
Set xlsWorkBook = Nothing '释放内存
Set xlsApp = Nothing  '释放Excel对象
Set subfolderobject=Nothing '释放内存
Set folderobject=Nothing '释放内存
Set fileapp=Nothing '释放内存



 
 
 
 
 

你可能感兴趣的:(Connection,VBScript,vbs,VBA)