Opening a Visio Document

Mr. Wizard

Board Regular
Joined
Sep 28, 2005
Messages
67
I have a Visio Drawing that represents a schedule. Since the information to generate the schedule is in a database, I would like to use Excel to query the database and generate the schedule drawing elements. I have a Visio Stencil that will come up if I use a default drawing as a template, and this will allow me to drop the shapes on the Visio Drawing from the shape master.

I would like to drive Visio from Excel, so the result for the user is one-touch generation of a Visio schedule. I have referenced the Visio Library in Excel VBA Editor. I have tried recording the macro to open a file in Visio and copying it into Excel after I opened an instance of Visio, but I get an error.

It seems like this would be rather straight-forward, but it escapes me so far.

How do I open the specific Visio Drawing file in an instance of Visio driven by the Excel macro?

Here is where I've gone so far...

Public Sub VISO_text()

Dim objVis As New Visio.Application

Set objVis = New Visio.Application
Application.Documents.OpenEx "C:\DefaultSchedule.vsd", visOpenRW
Application.Windows.ItemEx("Drawing1").Activate
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Mr. Wizard

Board Regular
Joined
Sep 28, 2005
Messages
67
Here is the solution to my problem. As usual, after diligent search, I find a working solution here:

Sub DefaultBarChart()

Dim objVisio As Visio.Application

Set objVisio = CreateObject("Visio.Application")

With objVisio
'.Visible = False
.Documents.OpenEx "C:\DefaultSchedule.vsd", visOpenRW

' other stuff to create & manipulate Visio objects
End With

End Sub
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I think it would be more like:

Code:
Public Sub VISO_text() 

Dim objVis As Object
Set objVis = CreateObject("Visio.Application")
objVis.Documents.OpenEx "C:\DefaultSchedule.vsd", visOpenRW 
objVis.Windows.ItemEx("Drawing1").Activate
 

Mr. Wizard

Board Regular
Joined
Sep 28, 2005
Messages
67
Thanks,

I will try it out, and see. The code I found as a solution does not work entirely with my drawing, so some revision is in order.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,535
Messages
5,572,747
Members
412,482
Latest member
arooshrana2
Top