Insert Field Showing Name/Title Of Another Page

Started by Anders, May 23, 2012, 04:28:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Anders

I can insert the current page's name by using Insert -> Field -> Page Info -> Name

Is it possible to insert the name of a different page that exists with the same Visio document? For example, with <Page 1> and <Page 2>, within a shape on <Page 1>, i'd like to insert text showing "Page 2".

I ask because I'd like to keep the text displayed within a shape, in line with the name of the page it refers to.

Visio 2007, Windows XP

Thanks for reading.

aledlund

I created a two page drawing and in the second page (Page-2)  I added a User section and a User Cell of "PageName",  in the value field I put in "PageName()"

On Page-1 I selected an object and inserted a field and selected custom forumula
"Pages[Page-2]!ThePage!User.PageName

hth,
al

Anders

#2
Oh wow, thanks, that worked a treat. You're well worthy of your title "Hero Member".

For others newbies looking at this, the "user-definded Cells" section is found under Window -> Show ShapeSheet (in Visio 2007 anyway).

As the custom forumula refers to the page name, I half expected this to break when I renamed the page, but it just works! Love it when that happens, although it makes me slightly nervous that it'll stop working later  ;)

aledlund

Don't get confused between the text assigned to the page (what you see on the bottom) and the page name. When a page is created the text and the name are the same, changing the text does not change the name.
al

Anders

Ah, so my gut was right, there is potential for error here.

For shapes, I can use Format -> Special, which gives me the name (I think!?). When I try this for a page, it's greyed over. The name displayed on the page's ShapeSheet (in the title bar), and on Page Setup - Page Properties tab, seem to keep synced with what is displayed on the tab.

Can you point me in the right direction for the page name please?

aledlund

when you do a show shapesheet for a page it's right at the top of the shapesheet window next to the file name. That holds true for shapes as well.

Drawing1.vsd:Page-1:ShapeA

al

Anders

Ah thanks, so far then, these seem to be keeping in sync, but at least I'll know where to check if it all goes wrong :)

Anders

Been using the custom formula method to good effect, but now one of my page's names is out of sync with the display title. At least that's my assumption, because the formula no longer works.

Using a test vsd, I've found it happens if a new word is inserted into a page's name. In the example screen shots, I renamed "Page-2 Test" to "Page-2 NewWord Test".

I was expecting to be able to see the name on the page's shapesheet, but this shows "Test.vsd:Page-2 NewWord Test <PAGE>"

The formula "=Pages[Page-2 NewWord Test]!ThePage!User.PageName" throws an error, but "=Pages[Page-2 Test]!ThePage!User.PageName" works.

Where do I find the page name ("Page-2 Test", in this example). I expect I'm just looking in the wrong place!?

aledlund

the first question is how did you change the page name (it has to be done via programming). The second issue is (if I remember correctly) is that names cannot have embedded spaces. That's why you see the special characters (I typically use an underscore rather than a space).
al

Anders

Good to see you again.

Nothing done programmatically by me. While I can program, I don't know how to do it in Visio. I change a page's display name by right clicking on the tab and picking Rename Page. Visio then updates the the page name and formula, but for some pages that has stopped. Consequntely, the page name is stuck at some (unknown) value. Using right click -> Rename Page to set the display name to something simple like "1" doesn't help either.

So is programmically changing the (stuck) page's names the best way forward?

Thanks.

aledlund

I may not get it done soon (possibly this evening), right now my day job is taking care of my granddaughter. I'll see what I can put together.
al

Anders

Thanks! The day job is defintely more important than this :) I'll manually type in names where I need to for the time being.

Jumpy

I guess it's the Name vs. NameU issue again. I seem to recall, that it's not only a shape, but also a page issue.
So in order to prevent that, you have to change the Name (what you do already) and the NameU of the page.

That can be done with Visio's Explorer-Window, or a macro like:


Sub ChangePageName()
  Dim NewName as String
  Dim pg as Page
  Set pg = ActivePage
 
  NewName = Inputbox("Insert new name, please:")
  If NewName<>"" Then
    pg.Name=NewName
    pg.NameU=NewName
  End If
End Sub


hth Jumpy

Anders

Thanks, that's spot on! I tweaked it so I have a version that simply sets NameU's value to Name's. Below in case it's useful to someone else:
Sub MatchPageName()
  Dim NewName As String
  Dim pg As Page
  Set pg = ActivePage
 
  If pg.Name <> pg.NameU Then
        pg.NameU = pg.Name
        MsgBox "NameU changed" & vbCrLf & "Name: " & pg.Name & vbCrLf & "NameU: " & pg.NameU
  Else
        MsgBox "Names already match" & vbCrLf & "Name: " & pg.Name & vbCrLf & "NameU: " & pg.NameU
  End If
End Sub

In my testing, I've found there is a trigger (macro?) built into Visio that detects a change to NameU and updates exisiting custom formula. Seems odd that what ever normally keeps Name and NameU aligned decides to stop on the insertion of a new word into Name.

Jumpy

On that:
The first time you change the Name, the NameU will be changed, too.
Whenever you change the Name after that, NameU will not be changed along.

So after the second renaming the "connection" is broken and NameU differs from Name.

... and that is bad because NameU is the name used for reference in ShapeSheet-formulas or in VBA as "String-Item-Index".