Excelファイルの外部からExcelマクロを実行しようとしています。私は現在、コマンドラインから実行される ".vbs"ファイルを使用していますが、マクロが見つからないことを伝え続けます。ここで私は外部ExcelからExcelマクロをコマンドラインからVBScriptを使用して実行
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("test.xls")
objExcel.Application.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"
objExcel.Application.Run "Macro.TestMacro()"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit
とここを使用しようとしているスクリプトは、私がアクセスしようとしているマクロです:
Sub TestMacro()
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = "C:\Users\username\Desktop\" & "TestResult.txt"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'write project info and then a blank line. Note the comma is required
Write #fnum, "I wrote this"
Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, "I printed this"
Close #fnum
End Sub
私はこれまでのところ(と修正を取得するためにIs it possible to run a macro in Excel from external command?に位置ソリューションを試してみましたもちろん)それは動作するように見えませんでした。 Microsoft Office Excel:マクロ 'Macro.TestMacro'が見つかりません。
EDIT:Excel 2003.
あなたが削除してみなかった "マクロを。"および/または括弧で囲み、これをobjExcel.Application.Run "TestMacro"のように呼び出すだけですか? – deusxmach1na
objExcel.Application.Run "test.xls!Macro.TestMacro" –
これらはどちらもうまくいきません:( – muttley91