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("文件路径") '

 

 

 

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页