newbie: link custom property to a separate text field

B

ben h

Hi all,
I have a macro that creates a new document based on a template. The
template has one background page and one foreground page, and a stencil.

Once the new drawing has been created, I add a bunch of custom
properties to the foreground page's PageSheet (values coming from a user
form type wizard thing). I figure that custom properties are pretty
versatile things and can be controlled by VBA pretty easily.

I use the foreground page's PageSheet for the custom properties so that
I can display it (the custom property window) as the user edits the
foreground page.

I want a particular custom property on the foreground page to control
the text in a text field that's on the background page somehow, so that
I can eventually lock the background, and the only way to change the
text field's text is by changing the custom property.

How can i control a text field on a background page from a custom
property on the foreground page? Is this a really awkward way of doing
this? Any suggestions or help would be great.

Ben
 
C

Chris Roth [ Visio MVP ]

Visio has the ability to do cross-sheet and cross-page formula references.
The syntax is below.

Put a cell "User.Bob" in the first page's ShapeSheet.

User.Bob = "Hello World"

Select a shape on the second page, and get into text-edit mode. Now from the
menu, select:

Insert > Field > Custom Formula

and paste this formula:

=pages[Page-1]!ThePage!User.Bob

You can see the syntax for cross-page referencing in the above formula.

--

Hope this helps,

Chris Roth
Visio MVP
 
B

ben h

Chris said:
and paste this formula:

=pages[Page-1]!ThePage!User.Bob

You can see the syntax for cross-page referencing in the above formula.

How do I programatically determine this sort of formula? For instance,
the above formula refers to a Page object's PageSheet ("ThePage"). How
would I go about crafting a formula for *any* object's shapesheet/cell
reference?

What I'm trying to do is create a function which will take a target
object, a source object (a shape maybe), and the source property name,
and set the target object's formula to the source object's property/cell
value.

vis:

Function SetCustomFieldFormula( _
vsoTargetShape As Visio.Shape, _
vsoSourceShape As Visio.Shape, _
strSourceRowNameU As String)

Dim strPropName As String
Dim blnExists As Boolean
Dim vsoCell As Visio.Cell

'' work with Custom Properties only:
strPropName = "Prop." & strSourceRowNameU

'' gets the characters of the target shape:
Dim vsoCharacters As Visio.Characters
Set vsoCharacters = vsoTargetShape.Characters

'' crafts the custom field formula:
'' ** this is the bit I fall over at **
'' ** I don't necessarily know it will be a PageSheet **
Dim strFormula As String
Dim strSheetname As String
strFormula = "Pages[" & _
vsoSourceShape.Parent.NameU & _
"]!ThePage!" & _
strPropName

'' sets the custom formula:
vsoCharacters.AddCustomFieldU strFormula, visFmtNumGenNoUnits

End Function
 
C

Chris Roth [ Visio MVP ]

I do string replacements:

sFormula = "Pages[[PAGENAME]]!ThePage![CELLNAME]"
sFormula = Replace(sFormula, "[PAGENAME]", visPgTo.Name)
sFormula = Replace(sFormula, "[CELLNAME]", visCell.Name)

visShp.Cells("User.Text").Formula = sFormula

or something similar.

--

Hope this helps,

Chris Roth
Visio MVP


ben h said:
Chris said:
and paste this formula:

=pages[Page-1]!ThePage!User.Bob

You can see the syntax for cross-page referencing in the above formula.

How do I programatically determine this sort of formula? For instance, the
above formula refers to a Page object's PageSheet ("ThePage"). How would I
go about crafting a formula for *any* object's shapesheet/cell reference?

What I'm trying to do is create a function which will take a target
object, a source object (a shape maybe), and the source property name, and
set the target object's formula to the source object's property/cell
value.

vis:

Function SetCustomFieldFormula( _
vsoTargetShape As Visio.Shape, _
vsoSourceShape As Visio.Shape, _
strSourceRowNameU As String)

Dim strPropName As String
Dim blnExists As Boolean
Dim vsoCell As Visio.Cell

'' work with Custom Properties only:
strPropName = "Prop." & strSourceRowNameU

'' gets the characters of the target shape:
Dim vsoCharacters As Visio.Characters
Set vsoCharacters = vsoTargetShape.Characters

'' crafts the custom field formula:
'' ** this is the bit I fall over at **
'' ** I don't necessarily know it will be a PageSheet **
Dim strFormula As String
Dim strSheetname As String
strFormula = "Pages[" & _
vsoSourceShape.Parent.NameU & _
"]!ThePage!" & _
strPropName

'' sets the custom formula:
vsoCharacters.AddCustomFieldU strFormula, visFmtNumGenNoUnits

End Function
 

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