S
stephenoye
Hi,
Hoping someon can help me out here.
I have made a some customized shapes and a customized stencil which I would
like to use in my VBA program. However, the program only runs as far as the
"shapes" line and throws out a run-time error.
It works alright if I use the generic blocks but I need to use my own.
Can anyone help.
I've gone back to the roots and copied an example that I know works just to
make sure I have no typos.
The only bits I have changed are the stencil and the the shapes ie .vst &
..vss.
The program is happy with the stencil but not the .vss.
Any help will be appreciated.
Program below:
Sub AutoVisio()
Dim AppVisio As Visio.Application ' Declare an Instance of Visio.
Dim docsObj As Visio.Documents ' Documents collection of instance.
Dim DocObj As Visio.Document ' Document to work in.
Dim stnObj As Visio.Document ' Stencil that contains master.
Dim mastObj As Visio.Master ' Master to drop.
Dim pagsObj As Visio.Pages ' Pages collection of document.
Dim pagObj As Visio.Page ' Page to work in.
Dim shpObj As Visio.Shape ' Instance of master on page.
' Create an instance of Visio and create a document based on the
' Basic Diagram template. It doesn't matter if an instance of
' Visio is already running, CreateObject will run a new one.
Set AppVisio = CreateObject("visio.application")
Set docsObj = AppVisio.Documents
' Create a document based on the Basic Diagram template that
' automatically opens the Basic Shapes stencil.
Set DocObj = docsObj.Add("Trend.vst")
Set pagsObj = AppVisio.ActiveDocument.Pages
' A new document always has at least one page, whose index in the
' Pages collection is 1.
Set pagObj = pagsObj.Item(1)
Set stnObj = AppVisio.Documents("Trend.vss")
Set mastObj = stnObj.Masters("delay")
' Drop the rectangle in the approximate middle of the page.
' Coordinates passed with the Drop method are always inches.
Set shpObj = pagObj.Drop(mastObj, 4.25, 5.5)
' Set the text of the rectangle.
shpObj.Text = "This is some text."
' Save the drawing and quit Visio. The message pauses the program
' so you can see the Visio drawing before the instance closes.
DocObj.SaveAs "MyDrawing.vsd"
MsgBox "Drawing finished!", , "AutoVisio (OLE) Example"
' Quit Visio.
AppVisio.Quit
' Clear the variable from memory.
Set AppVisio = Nothing
End Sub
Hoping someon can help me out here.
I have made a some customized shapes and a customized stencil which I would
like to use in my VBA program. However, the program only runs as far as the
"shapes" line and throws out a run-time error.
It works alright if I use the generic blocks but I need to use my own.
Can anyone help.
I've gone back to the roots and copied an example that I know works just to
make sure I have no typos.
The only bits I have changed are the stencil and the the shapes ie .vst &
..vss.
The program is happy with the stencil but not the .vss.
Any help will be appreciated.
Program below:
Sub AutoVisio()
Dim AppVisio As Visio.Application ' Declare an Instance of Visio.
Dim docsObj As Visio.Documents ' Documents collection of instance.
Dim DocObj As Visio.Document ' Document to work in.
Dim stnObj As Visio.Document ' Stencil that contains master.
Dim mastObj As Visio.Master ' Master to drop.
Dim pagsObj As Visio.Pages ' Pages collection of document.
Dim pagObj As Visio.Page ' Page to work in.
Dim shpObj As Visio.Shape ' Instance of master on page.
' Create an instance of Visio and create a document based on the
' Basic Diagram template. It doesn't matter if an instance of
' Visio is already running, CreateObject will run a new one.
Set AppVisio = CreateObject("visio.application")
Set docsObj = AppVisio.Documents
' Create a document based on the Basic Diagram template that
' automatically opens the Basic Shapes stencil.
Set DocObj = docsObj.Add("Trend.vst")
Set pagsObj = AppVisio.ActiveDocument.Pages
' A new document always has at least one page, whose index in the
' Pages collection is 1.
Set pagObj = pagsObj.Item(1)
Set stnObj = AppVisio.Documents("Trend.vss")
Set mastObj = stnObj.Masters("delay")
' Drop the rectangle in the approximate middle of the page.
' Coordinates passed with the Drop method are always inches.
Set shpObj = pagObj.Drop(mastObj, 4.25, 5.5)
' Set the text of the rectangle.
shpObj.Text = "This is some text."
' Save the drawing and quit Visio. The message pauses the program
' so you can see the Visio drawing before the instance closes.
DocObj.SaveAs "MyDrawing.vsd"
MsgBox "Drawing finished!", , "AutoVisio (OLE) Example"
' Quit Visio.
AppVisio.Quit
' Clear the variable from memory.
Set AppVisio = Nothing
End Sub