Opening an excel file manually allows formulas to run, opening an excel file with VBScript or PowerShell or Python's win32com doesn't

前端 未结 3 1116
长发绾君心
长发绾君心 2021-01-13 18:11

I\'m having a problem with a script not updating an excel file, and I reduced it to the following problem:

If I open an excel file, I can go to the Formulas tab and

相关标签:
3条回答
  • 2021-01-13 18:30

    Try adding a module with this in it

        Sub Auto_Open()
            ActiveWorkbook.RefreshAll
            Calculate
        End Sub
    
    0 讨论(0)
  • 2021-01-13 18:34

    Try this. Just for testing.

    ' Launch Excel...
    CreateObject("WScript.Shell").Run "excel.exe"
    
    ' Wait for it to load...
    WScript.Sleep 5000
    
    ' Get the running instance...
    Set Excel = GetObject(, "Excel.Application")
    
    ' Open your workbook...
    Excel.Workbooks.Open strPath
    
    ' Now go and click the Calculate button and see if it works.
    
    0 讨论(0)
  • 2021-01-13 18:37

    I found the problem, opening excel pages with VBScript (or Powershell) doesn't automatically include the Addins that are included when opening manually, so I needed to manually add these two addins.

    excel.AddIns.Add("C:\Program Files (x86)\PIPC\Excel\PITrendXL.xla").Installed = True
    excel.AddIns.Add("C:\Program Files (x86)\PIPC\Excel\pipc32.xll").Installed = True
    
    0 讨论(0)
提交回复
热议问题