Link to home
Start Free TrialLog in
Avatar of khott2003
khott2003

asked on

How can I save a Visio page navigation history?

Hello,

I am trying to create a page navigation code for a Visio document similar to that of Internet browsers.

This is how I imagine the logic would work:

1. The User clicks to navigate away from the current page
2. Before switching the page, Visio saves the current page name as a variable
3. The User can press a back button, which retrieves the previous page name from the variable

 Is there a way to save the current page name as a variable that can be retrieved at a later time?

Thanks!
Kyle
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

Yes, you can save page names in variables... but I'm not sure you need to.

The easiest thing to do is to save your Visio drawing as a web page (File/Save as Web Page). The result is a mini-website that is viewed and navigated in Internet Explorer so it behaves exactly like web browsing!

If you want to do the "browsing" from within Visio, there are a couple of alternatives that will require either macro programming or shapesheet formulas and functions.

Let me know which path you'd like to pursue...

Scott
Avatar of khott2003
khott2003

ASKER

I am looking for "browsing" within Visio.

We want to have the browsing history because the document is a "drill-down", where the user will start at a high level diagram and which linkes to pages with increasing levels of details. He/She needs to be able to edit the pages as he/she goes (which is why we don't want it as a web page). The "browsing" history will make navigation through the document much simpler.

I decided that the only things holding me back are:

I can't get the page history combo box list to refresh without reloading the whole toolbar. I can't figure out how to reference it as a control and add an event (like DropButtonClick) like you would for a normal control in the drawing.

The other obstacle is that there is no document event (that I am aware) for switching between pages in Visio. The user has to save the current page name by clicking "Save Page History" on the toolbar, which is tedious and would most likely not happen. The page history is updated if they browse using the navigation bar, but that isn't practical for our application.


Here is the code I have so far. The macro toolbar has other functions on it, so please comment out any errors you receive. I would separate the browsing part into another toolbar once I get it all working.
'Save global pagenames
Global lastpage1 As String
Global lastpage2 As String
Global lastpage3 As String
 
 
'---------------
 
Sub SetLastPages()
'Add current page to page history
 
'Check to see if current page is most recent saved page
If lastpage1 <> Application.ActivePage.Name Then
 
    'Move pages lower in history
    If lastpage3 <> lastpage2 Then
    lastpage3 = lastpage2
    End If
 
    'Move pages lower in history
    If lastpage2 <> lastpage1 Then
    lastpage2 = lastpage1
    End If
 
    'Set current page to most recent
    lastpage1 = Application.ActivePage.Name
 
End If
 
'Check for correct page name
'MsgBox lastpage1, , "Saved last page name"
 
'Refresh Toolbar List
MacroToolbar
 
End Sub
 
 
'--------------
 
Sub GoToPage()
 
Dim pagename
 
'Retrieve commandbar combo box page history value
pagename = Application.CommandBars("Navigation").Controls(6).Text
 
'Activate selected page from combobox
Application.ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU(pagename)
 
'Add current page to page history
SetLastPages
 
End Sub
 
 
 
'----------
 
Sub GoToLastPage()
 
If lastpage1 <> Application.ActivePage.Name Then
    Application.ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU(lastpage1)
  
    Else
    Application.ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU(lastpage2)
    
End If
 
End Sub
 
 
 
'-------
 
 
 
Sub MacroToolbar()
 
Dim picPicture As IPictureDisp
    
Set picPicture = stdole.StdFunctions.LoadPicture("P:\sheep.gif")
 
 
On Error Resume Next
Application.CommandBars("Navigation").Delete
On Error GoTo 0
 
With Application.CommandBars.Add("Navigation")
    .Visible = True
    .Position = visBarBottom
End With
    
    
    ' Item ID 1
With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
    .Caption = "World Tom"
    .OnAction = "Module1.Macro"
    .Style = msoButtonIconAndCaption
    .Picture = picPicture
End With
  
  
  ' Item ID 2
  With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
    .Caption = "Hide Layers"
    .OnAction = "NewMacros.Hidelayers"
    .Style = msoButtonIconAndCaption
    .FaceID = 3
End With
  
  
  ' Item ID 3
    With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
        .Caption = "Add To Layers"
    .OnAction = "NewMacros.hidealllayers"
    .Style = msoButtonIconAndCaption
    .FaceID = 2
End With
  
  
 ' Item ID 4
With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlComboBox)
    .Width = 150
    .Caption = "Layers"
    .OnAction = "NewMacros.Layers"
    .Text = "Select Layer"
    .Style = msoButtonAutomatic
    .Tag = .Caption
    .AddItem "Refresh"
End With
  
 
    
' Item ID 5
      With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
        .Caption = "Combo Box Value"
    .OnAction = "NewMacros.mmmValues"
    .Style = msoButtonIconAndCaption
    .FaceID = 20
End With
 
' Item ID 6
    
    Dim combobox As CommandBarComboBox
    Set combobox = Application.CommandBars("Navigation").Controls.Add(Type:=msoControlComboBox) 'Application.CommandBars("Navigation").Controls(4)
    
With combobox
    .Width = 150
    .Caption = "History"
    .Text = "Select Page"
    .AddItem lastpage1
    .AddItem lastpage2
    .AddItem lastpage3
    .OnAction = "Module1.Gotopage"
    .Style = msoButtonAutomatic
    .Tag = .Caption
    '.change = new Application.commandbarcomboboxevents_changeeventHandler(combobox_Change)
End With
  
  
' Item ID 7
      With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
        .Caption = "Save Page History"
    .OnAction = "Module1.Setlastpages"
    .Style = msoButtonIconAndCaption
    .FaceID = 200
End With
  
  ' Item ID 8
      With Application.CommandBars("Navigation").Controls.Add(Type:=msoControlButton)
        .Caption = "Previous Page"
    .OnAction = "Module1.GoToLastPage"
    .Style = msoButtonIconAndCaption
    .FaceID = 215
End With
  
  
End Sub

Open in new window

SOLUTION
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the point in the right direction!!

I am unsure of how to apply this event to a code. For instance in the code below, I would like to test it by showing the message box "Hello World!"



Here is the information from the MSDN:

Syntax

Private Sub expression_BeforeWindowPageTurn(ByVal Window As [IVWINDOW])

expression   A variable that represents a Window object.

Parameters
Name      Required/Optional      Data Type      Description
Window      Required      [IVWINDOW]      The window that is going to show a different page.
'In ThisDocument:
 
Public Sub Window_BeforeWindowPageTurn(ByVal Window As IVWindow)
 
MsgBox ("Hello World!")
 
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alright, I got it all working. Thanks for everything!!

I had to add:
Private Sub wdw_WindowTurnedtoPage(ByVal Window As IVWindow)
 
MacroToolbar
Layers
 
End Sub

Open in new window