本文主要是介绍vbs 关闭excel的piovt table自动刷新,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下(拷贝,将文件后缀修改为.vbs即可):
注:如果在运行时包字节错误,此问题是vbs文件编码在电脑中没有。简单的解决办法就是修改文件的编码格式(用text打开,另存为,选择编码格式。这里可以挨个选择,看那个可以运行就保存哪个)。另外一种就是在电脑的Region里面去配置,安装和vbs编码相同的环境
Function FilesTree(sPath)
dim oExcel,oWb,oSheet
set oExcel= CreateObject("Excel.Application")
'for each in folder all file
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(sPath)
Set oSubFolders = oFolder.SubFolders
Set oFiles = oFolder.Files
For Each oFile In oFiles
if instr(oFile,"~$") = 0 then
' WScript.Echo oFile.Path
'Set oWb = oExcel.Workbooks.Open(oFile,,false)
oExcel.DisplayAlerts = false
Set oWb = oExcel.WorkBooks.Open(oFile,false,false)
oExcel.DisplayAlerts = false
' Set oWb = myOBJ.WorkBooks.Open(FileName:= "XXX",, ReadOnly:=false)
'oWb.ActiveSheet.PivotTables("PivotTable1").PivotCache.RefreshOnFileOpen = false
oWb.Sheets("Summary report").PivotTables("PivotTable1").PivotCache.RefreshOnFileOpen = false
' set oFile = replace(oFile,"Test","Test2")
' oWb.SaveCopyAs(replace(oFile,"AAA","BBB"))
oWb.save
oWb.Close 'SaveChanges = true
'oExcel.Quit
'oFile.Delete
end if
Next
'For Each oSubFolder In oSubFolders
' WScript.Echo oSubFolder.Path
'oSubFolder.Delete
' FilesTree(oSubFolder.Path)'递归
'Next
Set oFolder = Nothing
Set oSubFolders = Nothing
Set oFso = Nothing
msgbox "run successfully"
End Function
FilesTree("文件路径") '
这篇关于vbs 关闭excel的piovt table自动刷新的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!