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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从CMD运行并且遇到使用SaveAs的问题相关的知识,希望对你有一定的参考价值。

我能够连接到服务器上的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 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

以上是关于从CMD运行并且遇到使用SaveAs的问题的主要内容,如果未能解决你的问题,请参考以下文章

Android 逆向Android 逆向通用工具开发 ( Android 平台运行的 cmd 程序类型 | Android 平台运行的 cmd 程序编译选项 | 编译 cmd 可执行程序 )(代码片段

2013a 中的 Matlab Saveas 错误

SaveAs 产生不兼容的文件类型和扩展名错误(运行时错误 6294)

运行时错误“1004”:对象“_Workbook”的方法“SaveAs”失败

SaveAs 方法被配置为需要有根路径,而路径 <blah> 是没有根的

从viewPager片段(Kotlin)中获取用户输入信息