How to Excel VBA macro to run through many text files and export outputs?
In monarch 10.5 we had a reference tlb file to hook. We no longer use this version and have 17.1 now, but when we went to look for this file in the monarch folders we didn’t find it. Is this still how
Without it, it doesn’t recognize the new version when trying to set the object. Does this still function this way or has it changed as to how to create Monarch as an object to run?
Answers
-
Hi Madison,
In the newer version of Monarch (v2020+), there is no need to add a reference to Monarch.exe as long as Monarch is installed on a PC. If you installed Monarch 64-bit, then you should use Excel 64-bit for using Monarch COM.
The following VBA script worked fine in Excel 64-bit:
Sub test()
Dim monarchobj As Object
Dim Monver As Variant
Dim openfile, openmod As Boolean
Const reportfolder = "C:\mo\DW\desktop\Monarch Altair\com_test\reports\"
Const modelfolder = "C:\mo\DW\desktop\Monarch Altair\com_test\models\"
Const exportfolder = "C:\mo\DW\desktop\Monarch Altair\com_test\exports\"Set monarchobj = CreateObject("monarch32")
If monarchobj Is Nothing Then
Set monarchobj = CreateObject("Monarch32")
End IfMonver = monarchobj.Version
MsgBox (Monver)
openfile = monarchobj.SetReportFile(reportfolder & "classic.prn", False)
openmod = monarchobj.SetModelFile(modelfolder & "Lesson9.dmod")
If openfile = True And openmod = True Then
monarchobj.CurrentFilter = "Fandangos Records"
monarchobj.ExportTable (exportfolder & "Fandangos.xls")
monarchobj.CurrentFilter = "No Returns"
monarchobj.ExportTable (exportfolder & "No_Returns.xls")
Else
MsgBox ("errro")
End If
monarchobj.CloseAllDocuments
monarchobj.Exit
Set monarch = Nothing
End SubRegards
Mo
0