First-time poster here. I've written VBA within a Visio Document, which runs a ShapeReport and exports it as an Excel Workbook. In this code, I need to then activate that newly created workbook in order to run a separate macro on the exported data, but I can't figure out how to activate the workbook since I don't consistently know the name or file order (Workbooks(1) for example), and I can't set the export line as a variable. In the code below, I need the ActiveWorkbook.Name to print out the workbook that opens in the prior line. Best case would be to figure out how to assign that workbook to the ObjXLBook Variable to be able to easily reference it.
I've tried declaring a Workbook Variable and setting it equal to the line of code which exports/creates the Excel Workbook and I've tried doing nothing and structuring the macro under the assumption that the newly created Workbook would already be activated, but neither option worked.
Current Code:
Sub testExport()
Dim objXLApp As Object
Dim objXLBook As Excel.Workbook
Set objXLApp = CreateObject("Excel.Application")
'create new workbook via report export
'this is the workbook that I need to activate and/or assign
Visio.Application.Addons("VisRpt").Run ("/rptDefName=VarianceRep.vrd")
Debug.Print (ActiveWorkbook.Name)
Debug.Print (objXLBook.Name)
End Sub
Attempt 1: Assign Variable
Set objXLBook = Visio.Application.Addons("VisRpt").Run("/rptDefName=VarianceRep.vrd")
Attempting to set the variable results in "Compile Error: Expected Function or Variable". Leaving it blank results in "Run-time error '91': Object Variable or With block variable not set" and the debug printing nothing.
I need the debug to print out the name of the newly created workbook which contains the exported data. The second debug will only apply if I can assign the workbook to the objXLBook Variable as well.