Estoy tratando de ejecutar una macro de Excel desde fuera del archivo de Excel. Actualmente estoy usando un archivo ".vbs" que se ejecuta desde la línea de comandos, pero sigue diciéndome que no se puede encontrar la macro. Aquí es el guión que estoy tratando de utilizarEjecutar Excel Macro desde fuera de Excel mediante VBScript desde la línea de comandos
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
Y aquí es la macro que estoy tratando de acceso:
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
probé las soluciones ubicadas en Is it possible to run a macro in Excel from external command? para llegar hasta aquí (y modificado por supuesto), pero no pareció funcionar. Sigo recibiendo el error `Microsoft Office Excel: no se puede encontrar la macro 'Macro.TestMacro'.
EDIT: Excel 2003.
¿usted intentó retirar el "Macro". y/o el paréntesis y simplemente llámelo como este objExcel.Application.Run "TestMacro"? – deusxmach1na
objExcel.Application.Run "test.xls! Macro.TestMacro" –
Esos no funcionan tampoco :( – muttley91