Ok this one is a bit unusual.
I'm actually using an Alteryx Event to run Wscript.exe, to run a bit of VB code. The code is supposed to open a workbook and run a VBA macro in there.
VBA macro is fine, works like a charm when I run it manually. I have no issues in Alteryx, its the darn VB code I cant get right. Anyone here good with that?
Example code below, pinched from the internet. All it needs do is open the excel file, and run the single macro, then once the macro is done, stop and shut down the excel file.
I cant get it to work though. Error messages about not being able to access, or cant find, etc. Tried a few different things. The internet has various posts by people trying to achieve similar outcomes, but all examples/solutiion are just slighty different enough to not help me.
Anyone done anything like this before and can help with the right VB code? So the excel file containing the VBA macro is called AlteryxMacros.xlsm, and the macro saved in there is called Rename.
Below are two examples i've failed with:
1.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run \\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\StephenAllan\Alteryx\AlteryxMacros.xlsm!Sheet1.Rename
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
one thing seems to be how to call the macro and if its in a module or a sheet. I'm not sure if my macro is in sheet1 or a module, how do you tell?
2.
dim objExcel
set objExcel = CreateObject("Excel.Application")
objExcel.Visible = TRUE
objExcel.DisplayAlerts = FALSE
Path1="\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\StephenAllan\Alteryx\AlteryxMacros.xlsm"
Set objWorkbook = objExcel.Workbooks.Open(Path1, 0, True)
Dim fso, path, file, recentDate, recentFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\DCA\Invoices\Input\").Files
If (recentFile is Nothing) Then
Set recentFile = file
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
Set recentFile = file
End If
Next
If recentFile is Nothing Then
WScript.Echo "no recent files"
Else
objExcel.Workbooks.Open recentFile
End If
objExcel.Run("AlteryxMacros.xlsm!Rename")
objWorkbook.Saved=False
objExcel.quit
So in the above, much bigger example, the Macro ChangeSheetName is called without specifiying that its in sheet1. There's also a lot of extra code in the centre, sometthing about each file the the folder, but I dont see why that bit is needed. Just run the VBA macro!
Any help would be much appreciated.
Thanks
Stephen
I'm actually using an Alteryx Event to run Wscript.exe, to run a bit of VB code. The code is supposed to open a workbook and run a VBA macro in there.
VBA macro is fine, works like a charm when I run it manually. I have no issues in Alteryx, its the darn VB code I cant get right. Anyone here good with that?
Example code below, pinched from the internet. All it needs do is open the excel file, and run the single macro, then once the macro is done, stop and shut down the excel file.
I cant get it to work though. Error messages about not being able to access, or cant find, etc. Tried a few different things. The internet has various posts by people trying to achieve similar outcomes, but all examples/solutiion are just slighty different enough to not help me.
Anyone done anything like this before and can help with the right VB code? So the excel file containing the VBA macro is called AlteryxMacros.xlsm, and the macro saved in there is called Rename.
Below are two examples i've failed with:
1.
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run \\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\StephenAllan\Alteryx\AlteryxMacros.xlsm!Sheet1.Rename
objExcel.DisplayAlerts = False
objExcel.Application.Quit
Set objExcel = Nothing
one thing seems to be how to call the macro and if its in a module or a sheet. I'm not sure if my macro is in sheet1 or a module, how do you tell?
2.
dim objExcel
set objExcel = CreateObject("Excel.Application")
objExcel.Visible = TRUE
objExcel.DisplayAlerts = FALSE
Path1="\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\StephenAllan\Alteryx\AlteryxMacros.xlsm"
Set objWorkbook = objExcel.Workbooks.Open(Path1, 0, True)
Dim fso, path, file, recentDate, recentFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\uug.vcm.cc\Domestic_Retail\CollectionsAnalyticsTeam\DCA\Invoices\Input\").Files
If (recentFile is Nothing) Then
Set recentFile = file
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
Set recentFile = file
End If
Next
If recentFile is Nothing Then
WScript.Echo "no recent files"
Else
objExcel.Workbooks.Open recentFile
End If
objExcel.Run("AlteryxMacros.xlsm!Rename")
objWorkbook.Saved=False
objExcel.quit
So in the above, much bigger example, the Macro ChangeSheetName is called without specifiying that its in sheet1. There's also a lot of extra code in the centre, sometthing about each file the the folder, but I dont see why that bit is needed. Just run the VBA macro!
Any help would be much appreciated.
Thanks
Stephen