Saving Changes to A Master in a Stencil --> Help

M

M@

Hey,

I wish to add an Action to a Visio Master (Shape) in a stencil.
I can open the stencil, get the master, copy it, edit it, save the copy BUT
cannot save the changes to the stencil.
If I manually place the stencil in 'Edit' (Red *) then I am able to save the
changes.

My question is, how do I set the stencil to be edited, in VB. The return it
to the non-edit state after saving the changes to the master?

My code is as follows:
The error produced when executing the line 'StnObj.Save' is: Requested
Operation is Presently Disabled.

Public Sub AddRMouseMenuToMaster(strMasterShape As String, strVisioStencil
As String, strActionString As String)

Dim mastObj As Visio.Master
Dim mastObjCopy As Visio.Master
Dim StnObj As Visio.Document
Dim shpsObj As Visio.Shapes
Dim shpObj As Visio.Shape
Dim curShapeIndex As Integer
Dim cellObj As Visio.Cell

Set StnObj = Documents(strVisioStencil)
Set mastObj = StnObj.Masters(strMasterShape)
Set mastObjCopy = mastObj.Open
Set shpsObj = mastObjCopy.Shapes
Set shpObj = shpsObj(1)
Set cellObj = shpObj.Cells("Actions.Action")

' Add the action
cellObj.Formula = strActionString

mastObjCopy.Close
StnObj.Save
Set StnObj = Nothing

End Sub


Thanks
 
M

Mark Nelson [MS]

You must have the stencil open as Read-Write if you want to save changes.
By default stencils are open Read-Only. You should be able to use the
OpenEx method to specify the read-write flag.

There is no automation method equivalent to manually placing a stencil in
Edit mode. Close the stencil and reopen it or open it read-write to start
with.
 
M

M@

Thanks Mark ;-)

Following your suggestion I am re-opening using the OpenEx method (with
hidden and read-write flags set).

Set stnObj = Documents.OpenEx(strStencilPath & strVisioStencil, &H20 + &H10)

For the benifit of the forum heres the code... hope it helps :)
M@

<--------------------------------------->

Public Sub AddRMouseMenuToMaster(strMasterShape As String, strVisioStencil
As String, strStencilPath As String, strActionString As String,
strActionText As String)

Dim mastObj As Visio.Master, mastObjCopy As Visio.Master
Dim stnObj As Visio.Document
Dim shpsObj As Visio.Shapes, shpObj As Visio.Shape
Dim curShapeIndex As Integer
Dim cellObj As Visio.Cell
Dim strBaseID As String

' As the stencil is already Open its attributes will be set to
'Read-Only'.
' We cannot save to a Read-Only Stencil, so it must be closed then
re-opened as 'read-write'
' Close the Stencil (read-only version)
Set stnObj = Documents(strVisioStencil)
stnObj.Close

' Open the stencil with 'Read-Write' & 'Open-Minimized' attributes
Set stnObj = Documents.OpenEx(strStencilPath & strVisioStencil, &H20 +
&H10)
Set mastObj = stnObj.Masters(strMasterShape)
Set mastObjCopy = mastObj.Open

Set shpsObj = mastObjCopy.Shapes
Set shpObj = shpsObj(1)

strBaseID = mastObj.BaseID

' Manipulate the Shape
Set cellObj = shpObj.Cells("Actions.Action")
cellObj.Formula = strActionString

Set cellObj = shpObj.Cells("Actions.Menu")
cellObj.Formula = """" & strActionText & """"

' Close the Master
mastObjCopy.Close

' Save the stencil
stnObj.Save

' Close the stencil with read-write addributes
stnObj.Close
' Open the stencil with 'Read-Only' & 'Docked' Attributes
Set stnObj = Documents.OpenEx(strStencilPath & strVisioStencil, &H4)
Set stnObj = Nothing

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