Brian_Fitch24
asked on
Visio Macro Execution
I have a 3 part question:
1. Is there an Auto_Open Macro type in Visio, if so what is the syntax?
2. How do I execute a Visio Macro from Excel VBA?
3. How do I execute an Excel macro from Visio? - Excel.Application.Run???
1. Is there an Auto_Open Macro type in Visio, if so what is the syntax?
2. How do I execute a Visio Macro from Excel VBA?
3. How do I execute an Excel macro from Visio? - Excel.Application.Run???
ASKER
Hey Scott -
Sorry I didnt make it worth more points, I only had 265 left.
1. Looks good
2 & 3) I want code in a Visio document to execute a macro in an excel document and vice versa.
Thanks,
Brian
Sorry I didnt make it worth more points, I only had 265 left.
1. Looks good
2 & 3) I want code in a Visio document to execute a macro in an excel document and vice versa.
Thanks,
Brian
Brian,
There may be a better way than this but this Visio code opens an Excel sheet and uses the Excel Workbook_Open event to run the Excel macro.
You should be able to do the reverse to run a Visio macro from Excel, but let me know if you need help with that.
Scott
There may be a better way than this but this Visio code opens an Excel sheet and uses the Excel Workbook_Open event to run the Excel macro.
You should be able to do the reverse to run a Visio macro from Excel, but let me know if you need help with that.
Scott
IN EXCEL
Sub Workbook_Open()
' Runs whenever workbook is opened
MsgBox "Greetings from Excel workbook open macro", vbOKOnly
End Sub
IN VISIO
Sub CallMarcoInExcel()
' opens Excel workbook, which runs workbook_open macro contained in the workbook
'
' Add Reference to Excel to this VBA project before running macro
Dim xlApp As Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlDocPath As String
xlDocPath = "c:\Temp\Excel book with workbook_open macro.xls"
'Use existing Excel object or create a new one
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application") ' get ref if already running
If Err = 429 Then
Set xlApp = CreateObject("Excel.Application")
End If
'Bring Excel to front
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open(xlDocPath)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Scott -
Thanks so much for your help. I got it to work.
Brian
Thanks so much for your help. I got it to work.
Brian
If you want yet another approach, see this article by Chris Roth, aka the Visio Guy:
http://www.visguy.com/2007/05/25/run-vba-code-when-documents-open/
2) & 3) For these two questions I need to clarify what you want to do. Do you want to run Excel VBA code from within a Visio document (and vice versa)? Or do you want code running in a Visio document to execute a macro that lives in an Excel document (and vice versa)? I've used the former quite a bit, for example to create an Excel document based on data in a Visio drawing. I have done the latter, though I'm sure it's possible.
Open in new window