[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 599
  • Last Modified:

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
0
khott2003
Asked:
khott2003
  • 4
  • 2
2 Solutions
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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
0
 
khott2003Author Commented:
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

0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Actually, there is a BeforeWindowPageTurn Event -- I wasn't aware of it, probably for the same reason as you -- it doesn't show up in the VB Editor list (those are just the events for the Document object).

But I turned on the event monitor from the Visio SDK, monitored all events, then changed pages a couple of times. Almost lost in the flood, you'll find BeforeWindowPageTurn. A quick lookup in the SDK help text reveals that this is an event of the Application object.

I don't have time to fiddle with it at the moment but let me know if this helps.

Scott
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
khott2003Author Commented:
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

0
 
khott2003Author Commented:
I think I figured it out. Thanks!!

I am having an issue where my I would like my commmandbar combo boxes to update on each page change. I am working on it and will let you know what happens.

Thanks again!

'----------------------------------------
'Created a Class Module: clsWindowEvents
'Add the following code
 
 
Public WithEvents wdw As Windows
 
'--------
 
Private Sub wdw_BeforeWindowPageTurn(ByVal Window As IVWindow)
 
SetLastPages
 
End Sub
 
 
'-----------------------------------------
'In a regular Module I added:
 
 
Public window1 As New clsWindowEvents
 
'--------
 
Sub TrapClsWindowEvents()
 
    Set window1.wdw = Windows
 
End Sub
 
 
 
'-----------------------------------------
'In ThisDocument I added:
 
 
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
 
'Track Window Change Events
TrapClsWindowEvents
 
'Add Toolbar
MacroToolbar
 
End Sub

Open in new window

0
 
khott2003Author Commented:
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

0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now