Identifying Visio Pages with Unique IDs

Started by bouananimeher, September 23, 2011, 09:52:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bouananimeher

Hi ,
Well i am pretty new here and i am a beginer ,so i am asking if there is way to identify a visio page by it's unique ID or  any other ways , like tha case of Shapes which are identified by : Shape.UniqueID and Masters : master.uniqueID ...
Thank you

Paul Herber

#1
The Page.ID is constant, it doesn't change when the page gets renamed or the page order changes. The number may be reassigned though if the page is deleted and then a new page created.
http://msdn.microsoft.com/en-us/library/ff766565.aspx

How about when the page is created add a User defined cell and add your own unique ID to that cell.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

bouananimeher

#2
Thank you for aswering :) , no i am facing another problem  :-[ , i have some macros that are fully functional in vsd document (Dessin.vsd) and for now i am trying to get them functional for every document i create , but the problem is when i embed them into a Stencil some errors come out and i do not actualy know the reason , could you have an explanation for that ?

Jumpy

#3
Could you say more about the errors? It could matter, how the macros are called. Or the code project of the stencil has to be known to the drawing or vice versa.

Somewhere in this forum is a near tutorial like thread about placing code in stencils.

bouananimeher

#4
i have to Marcos , Macro1 which is processing on an IE instance , and Macro2 wich deals with MSSQL , i've created to buttons for these macros to execute them , and here is the souce code to do that : Sub CreateMyButtonBar()
Dim CB As CommandBar
Dim CBS As CommandBars
Set CBS = Application.CommandBars
Set CB = CBS.Add(CommandBarName, msoBarFloating)
AddButtonToBar CB, "Macro1", "Run security application", 186
AddButtonToBar CB, "Persist", "Persist Data", 180
CB.Visible = True
End Sub
Private Sub AddButtonToBar(Bar As CommandBar, _
MacroName As String, _
Caption As String, _
Button As Integer)
Dim CBC As CommandBarControl
Set CBC = Bar.Controls.Add(msoControlButton, 1, , , True)
CBC.Style = msoButtonAutomatic
CBC.FaceID = Button
CBC.Caption = Caption
CBC.OnAction = MacroName
End Sub
the problem still now where should i put the call of the function CreateMuButtonBar inside the page "ThisDocument" of the Stencil  in order to create these two buttons that appear each time i tried to open visio or when i create a new docuement or when i am working on an existing docuement !!?




Visio Guy

Visio pages also have a "page sheet", a ShapeSheet for the page. In this respect, they exhibit some shape-like behavior, from an automation standpoint.

You get at the shape-ish part of a page using visPg.PageSheet. Here we get a GUID from a page, just like we do for a shape:


'...
Debug.Print Visio.ActivePage.PageSheet.UniqueID(Visio.VisUniqueIDArgs.visGetOrMakeGUID)
'
'Result: {A8A24720-0C84-4FDC-8551-4265247DF2F6}



You would still need to loop through all the pages in a document find the right page with the right GUID, something like:


Function GetPageByID(ByRef visDoc as Visio.Document, ByVal guid as String) as Visio.Page

  Set GetPageByID = Nothing '...the default result.

  Dim pg as Visio.Page
  Dim guidPage as String

  For Each pg in visDoc.Pages
    guidPage = pg.PageSheet.UniqueID(visio.VisUniqueIDArgs.visGetGUID) '...get-only, not get or make!
    If (guidPage = guid) Then
      Set GetPageByID = pg
      Exit Function
    End If
  Next

End Sub

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

bouananimeher

Hi,

Thank you so much it solve a big problem. Now I can update an existing Diagram :D