Adding a docked stencil to a project template

L

Lant

I have used VBA and automated a Visio solution which brings up a drawing
template and some custom stencils docked on a side. In the course of user
interaction, I create some more new stencils (by dropping shapes on a drawing
page and assigning custome properties from the database). Once these custom
stencils are created, I would like to add (tile or layer like other stencils)
them to the other stencils.
I use the following steps to 'Create' , 'Add' , and 'Dock' the stencil. But
it does not get arranged along with the other stencils on the left of the
template. How do I fix it? I am not very clear about the object model -
document collection, document, sheet, windows, etc. in this context. Thanks
for any suggestions.

This is the code I have:
Set rsElements = New ADODB.Recordset
Set rsElements = conn.Execute(strSelect)
Set stencil = ThisDocument.Application.Documents.Open("SampleShape.VSS")

Dim vsoDocument As Visio.Document
Set vsoDocument = Application.Documents.Add(APPLOCATION & "blank.vsd")

Set mstElement = stencil.Masters("Element") ' Get the master named "Element"
and drop that shape on the page!

'Use the records to create Element Stencil
Do Until rsElement.EOF

Set elementShape = vsoDocument.Pages(1).Drop(mstElement, x, y)
elementShape.Text = rsElements!ElementName

'Set xy position
y = (y - 1)
If (y < 1) Then
x = x + 1
y = 10
End If
'Next Element
rsClientProducts.MoveNext

Loop
'Save file as Element Stencil file
vsoDocument.SaveAs "ElementStencil.vss"
Application.Documents.AddEx "ElementStencil.vss", visMSDefault, visAddDocked
+ visAddStencil
 
J

junethesecond

Please, try SaveAsEx method,
Document.SaveAsEx FileName, &H2
and open the saved drawing again.
 
L

Lant

The 'SaveAsEx' followes by 'open' did not work either as the saved stencil
did not display like a regular stencil though it behaved like one. The
stencil displayed the masters on the drawing page.

I found something which solves this. Create a stencil by Dropping shapes
onto a new stencil opened using AddEx("vss", 0, visAddDocked) and do a
'SaveAsEx "StencilName.vss", visAddDocked.

I am not sure if there is some problem with this approach of creating
stencils because twice in this usergroup I was advised to create stencils by
dropping shapes on a Drawing page and saving it as Stencil. So far the
stencil works fine. Any feedback appreciated.

Thanks
 
J

junethesecond

Sorry, my explanation was insufficient.
If the current drawing is saved by
SaveAsEx visSaveAsWS (or &H2),
docked stencils are saved with the drawing,
for example,
ThisDocument.SaveAsEx Name.vsd, visSaveAsWS .
 
J

junethesecond

made a simple skelton.

Sub test()
Dim Stn As Visio.Document
Dim strPath As String
strPath = "C:\Documents and Settings\Mary\My Documents\"
Set Stn = ThisDocument.Application.Documents.AddEx("vss", visMSMetric,
visAddDocked)
Stn.SaveAs strPath & "NewStencil.vss"
ThisDocument.SaveAsEx strPath & "NewDrawing.vsd", visSaveAsWS
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top