Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel Runmacro
#1
Is possible run a excel macro saved in str variable?
#2
Exact macro - probably not. But look in Excel COM interfaces, maybe you can add macro to Excel and then run it.

Or change it a little and run with VbsExec.
#3
I found:

VBScript - Add a Macro to an Excel Spreadsheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False

Set objWorkbook = objExcel.Workbooks.Open("C:\scripts\test.xls")
Set xlmodule = objworkbook.VBProject.VBComponents.Add(1)

strCode = _
"sub test()" & vbCr & _
" msgbox ""Inside the macro"" " & vbCr & _
"end sub"

xlmodule.CodeModule.AddFromString strCode
objWorkbook.SaveAs "c:\scripts\test.xls"
objExcel.Quit

can you help to convert to QM function?
#4
Macro Macro1416
Code:
Copy      Help
;/exe 1
ExcelSheet es.Init
Excel.Workbook wb=es.ws.Application.ActiveWorkbook

;use IDispatch because I don't know in which type library is VBProject
IDispatch objWorkbook=wb
IDispatch xlmodule = objWorkbook.VBProject.VBComponents.Add(1)
err mes- "Failed. You probably need to change Excel security settings.[][]Click menu Tools -> Macro -> Security.[]In Publishers tab check 'Trust access to Visual Basic project'." "" "x"

str strCode =
;sub test()
;;msgbox "Inside the macro"
;end sub
;
xlmodule.CodeModule.AddFromString(strCode)

test
Macro Macro1418
Code:
Copy      Help
;/exe 1
act "Excel"
ExcelSheet es.Init
es.RunMacro("test")
#5
Thanks.


Forum Jump:


Users browsing this thread: 1 Guest(s)