从CMD运行并且遇到使用SaveAs的问题

问题描述 投票:1回答:1

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

另一方面,我发出的错误是:

Object不支持此属性或方法:'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 Files\SAP Shared\BW\BExAnalyzer.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:\Output\NAME.xlsm"
'xl.SaveAs "C:\Output\NAME", 52 ' 52 should be the format for XLSM
Application.DisplayAlerts = True

'' Close Excel
'xl.Quit

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

excel vbscript
1个回答
1
投票

你的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 Files\SAP Shared\BW\BExAnalyzer.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:\Output\NAME.xlsm"
'xl.SaveAs "C:\Output\NAME", 52 ' 52 should be the format for XLSM
Application.DisplayAlerts = True


'' Close Excel
'xl.Quit
© www.soinside.com 2019 - 2024. All rights reserved.