How to get page GUID?

Started by Ana, March 13, 2012, 11:21:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ana

I have a series of 30+ page diagrams with many off-page references, the off-page references are marked with the page they go to. For example, page 5 has links to pages 6, 8-12, and 23-25 labeled with the respective page numbers; the returning links are all labeled  5. When a page is added, the labeled need to be updated accordingly.

I have a macro that changes the text according to hyperlink subaddress, however, if a page name is changed the macro breaks. Is there a way to get the GUID of each page?

I can get the User.OPCDPageID from the off-pconnectoretor shape, but I need to compare it to the

gotoPage = remove quote marks from obj.CellsSRC(<User.OPCDPageID info>).Formula
for each p in ActiveDocument.Pages
      if p.? = gotoPage then obj.Text = index of the page
next p

thanks,
Ana

aledlund

AFAIK a guid is not automatic, it has to be created via code and then you can assign it. The ID of a page is an integer assigned when the page is created. The page ID is actually stored in the pagesheet

....
set visPage = visapp.activepage
dim visPS as visio.shape
set visPS = visPage.pagesheet
msgbox visPS.ID ' gives you the pageID
....

al

JohnGoldsmith

Just to add to Al's answer, as Al points out, shapes (of which the page's PageSheet is a type) don't automatically get a guid but you can retrieve or generate one via the Shape.UniqueID property and pass it a visGetOrMakeGUID enum.  See this link for more info:

http://msdn.microsoft.com/en-us/library/ff767736.aspx

Just as an observation, though, if your objective is to keep the text synchronised, then this functionality already exists in the OPC addon.  I maybe misunderstanding your labeling requirements but if you check the dialog there's a "Keep shape text synchronised" checkbox.  Checking this adds the following formula:

=RUNADDONWARGS("OPC","/CMD=3")

...to the 'TheText' cell of the 'Events' section of the ShapeSheet, which you can add in your code if you want to update previously dropped shapes.

Hope that helps.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Ana

Al, I can get the GUID of the shapes in the page, what I need is to be able to compare the User.OPCDPageID of the off page connector to the GUID of the pages...

John, the text in the object cannot be synchronized, I need the values to be different.

Here is the code:

Function pageID(ByVal uniqueID As String) ' uniqueID is either User.OPCDShapeID or User.OPCDPageID of the connector to update

    'ensure that the incoming string does not have any extra quote marks
    uniqueID = Replace(uniqueID, Chr(34), "")
   
    pageID = Null
    For Each p In ActiveDocument.pages
        If p.<the GUID I need> = uniqueID Then
            pageID = p
            Exit For
        Else       
                For Each s In p.Shapes
                    If s.uniqueID(visGetOrMakeGUID) = uniqueID Then
                        pageID = p
                        Exit For
                        Exit For
                    End If
        End If
        Next s
    Next p

End Function

JohnGoldsmith

Hello Ana,

Well, as Al suggests, you just use the PageSheet property of the page object to get hold of the underlying Shape object.  Once you've got that you can use the UniqueID property as per a standard shape.  So your modified code would look like this:

Dim p As Page
    For Each p In ActiveDocument.Pages
        If p.PageSheet.uniqueID(visGetOrMakeGUID) = uniqueID Then
            pageID = p.ID

Hope that helps.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Ana