从CMD运行并在使用SaveAs时遇到问题



我可以连接到服务器上的SAP BW(商业仓库(以打开特定查询,但最终无法保存它。我试图在各种论坛上搜索,但它们都使用与我相同的逻辑。我正在使用CMD运行此脚本。

另一方面,我的抛出了一个错误,即:

对象不支持此属性或方法:"SaveAs">
型号:800A01B6

' Setup the global variables
Dim xl
Dim myConnection
Dim xlBook
 
' Launch Excel
Set xl = CreateObject("Excel.Application")
 
' Make it visible otherwise things just don't work well
xl.Visible = True
     
' Now that Excel is open, open the BEX Analyzer Addin xla file
xl.Workbooks.Open ("C:Program Files (x86)Common FilesSAP SharedBWBExAnalyzer.xla")
' Run the SetStart macro that comes with BEX so it pays attention to you
xl.Run ("BExAnalyzer.xla!SetStart")
 
' Logon directly to BW using the sapBEXgetConnection macro
Set myConnection = xl.Run("BExAnalyzer.xla!sapBEXgetConnection")
With myConnection
    .client = "100"
    .User = "user"
    .Password = "pass"
    .Language = "EN"
    .systemnumber = 00
    .ApplicationServer = "xxxyyy"
    .SAProuter = "xxxyyyyy"
    .Logon 0, True
End With
' Now initialize the connection to make it actually usable
xl.Run ("BExAnalyzer.xla!sapBEXinitConnection")
' Open query
xl.Run "BExAnalyzer.xla!runQuery","00O2TPBVULP4LPJ4LBZRIFQN3" 
' Initiate saving, turn off showing allerts
Application.DisplayAlerts = False
xl.SaveAs "C:OutputNAME.xlsm"
'xl.SaveAs "C:OutputNAME", 52 ' 52 should be the format for XLSM
Application.DisplayAlerts = True
'' Close Excel
'xl.Quit

我想将 XLSM 保存到特定文件夹。

您的xl对象是指Application对象。 SaveAsWorkbook对象的成员。 设置对工作簿的引用并使用它来执行保存操作

' Setup the global variables
Dim xl
Dim myConnection
Dim xlBook
' Launch Excel
Set xl = CreateObject("Excel.Application")
' Make it visible otherwise things just don't work well
xl.Visible = True
' Now that Excel is open, open the BEX Analyzer Addin xla file
Set xlBook = xl.Workbooks.Open ("C:Program Files (x86)Common FilesSAP SharedBWBExAnalyzer.xla")
' Run the SetStart macro that comes with BEX so it pays attention to you
xl.Run ("BExAnalyzer.xla!SetStart")
' Logon directly to BW using the sapBEXgetConnection macro
Set myConnection = xl.Run("BExAnalyzer.xla!sapBEXgetConnection")
With myConnection
    .client = "100"
    .User = "user"
    .Password = "pass"
    .Language = "EN"
    .systemnumber = 00
    .ApplicationServer = "xxxyyy"
    .SAProuter = "xxxyyyyy"
    .Logon 0, True
End With

' Now initialize the connection to make it actually usable
xl.Run ("BExAnalyzer.xla!sapBEXinitConnection")
' Open query
xl.Run "BExAnalyzer.xla!runQuery","00O2TPBVULP4LPJ4LBZRIFQN3" 
' Initiate saving, turn off showing allerts
Application.DisplayAlerts = False
xlBook.SaveAs "C:OutputNAME.xlsm"
'xl.SaveAs "C:OutputNAME", 52 ' 52 should be the format for XLSM
Application.DisplayAlerts = True

'' Close Excel
'xl.Quit

相关内容

最新更新