thegameoflife
Programmer
Is there a way to run an Excel macro and pass a string to the macro? I have the code to run the macro but I can't pass a string to excel.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub XLTest(exlpath)
Dim TemplateFile As String
Dim XLApp As Object
TemplateFile = "C:\Recoveries\AIM_HRI.xls"
On Error Resume Next 'ignore error if Excel not running
Set XLApp = GetObject("Excel.Application") 'Check for Excel
If Err <> 0 Then
Set XLApp = CreateObject("Excel.Application") 'Open Excel
End If
XLApp.Visible = True 'Make Excel Visible
XLApp.Workbooks.Open TemplateFile 'Open the spreadsheet
'XLApp.Workbooks.Open exlpath
XLApp.ActiveWorkbook.Application.Run "AIMHRI", exlpath 'run excel macro and PASS the string
End Sub