Open Document Stencil with VBA

R

rhatcher

Im trying to open the Document Stencil from VBA using the following
code, replacing ("basic shapes.vss") with ("Document Stencil".vss"),
which doesnt work. the code as it is works fine. It would be great if
someone could set me strait.

Sub GetStencil()

'If file is not open, open it
On Error Resume Next

'Get a refernce to the stencil object
Set StnObj = Documents("basic shapes.vss")

'the stencil was not opened, open it
If StnObj Is Nothing Then
Set StnObj = Documents.OpenEx("basic shapes.vss", visOpenRO)
End If

End Sub

Also, I want to change one cell in a master on the document stencil. A
snippit of code or some pointers to start with would be great. I have
plenty of references, but Im not finding a way to do this, yet

Thanks
Robert
 
A

Al Edlund

well a couple of things a.) you have three quotation marks in your "document
stencil" example, and b.) the document stencil is not a file. The masters
used in a document are stored in the document. You might try
something like this for a master called pattern1...

doc As Visio.Document
Set doc = ThisDocument

doc.Masters("pattern1").PatternFlags = visMasIsFillPat + visMasFPTile

al
 
R

rhatcher

thanks Al, the obvious defeats me again!

That code works as it is, but when I try to change a cell value of the
shape I want to edit, I find that a Master does not have cell Cell
Property.

To test I was trying this:

Sub changeIt()
Dim doc As Visio.Document
Set doc = ThisDocument
doc.Masters("Master.0").Cells("fields.value0") = "it worked"
End Sub

but get the error that the property doesnt exists for this object. Im
caught in its a Shape and a Master at the same time, ThisDocument
doesnt have a Shape property and a Master doesnt have the Cells
property I need to change.
 
J

JuneTheSecond

String have to be double quated for the Visio cells, for example,
..... Chr(34) & "it worked" & Chr(34)
 
A

Al Edlund

try this ....

Sub changeIt()

Dim doc As Visio.Document
Dim cell As Visio.cell
Dim lclMaster As Visio.Master
Dim cpyMaster As Visio.Master
Dim mstShape As Visio.Shape
Dim lclCell As Visio.cell

Dim strShape As String
Dim strCell As String

' dropped a square on the page
strShape = "square"
' pick the cell
strCell = "FillForegnd"

Set doc = ThisDocument

' find the master we want
Set lclMaster = doc.Masters(strShape)
' test to see if the cell we want is there
If lclMaster.Shapes.Item(1).CellExists(strCell, False) Then
' make a copy of the master
Set cpyMaster = lclMaster.Open
' edit the master
Set lclCell = cpyMaster.Shapes.Item(1).Cells(strCell)
' change the color of the shape on the page
lclCell = visGreen
' close the copy so that it can merge
cpyMaster.Close
Else
MsgBox "Couldnt find " & strCell & " in the shape "
Exit Sub
End If


End Sub

al
 
R

rhatcher

Al, That works great, and I understand how to edit a master on a
stencil.

Thanks for the lesson
 

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