change the background of a page when the page orientation changes

G

Garrett

I have a landscape background page for landscape foreground pages and a
portrait background page for portrait foreground pages. Is there an easy way
to automatically set the background page based on the print orientation or is
VBA the best way to go?

I am able to change the background of a page using:
Visio.Application.ActivePage.BackPage = "My Background Page Name"

But I am not sure what I should trigger off of to change my background page.
Can someone point me at an event and possibly a code snippet or example?

Thanks in advance.
Garrett
 
J

JuneTheSecond

I don't know enough about printing, so I am no sure what is meet with your
needs.
If you wish to change print orientatio to fit to the foreground page,
Dim myBackPage As Visio.Page
Set myBackPage = ActivePage.BackPage
myBackPage.PageSheet.Cells("PrintPageOrientation") = _
ActivePage.PageSheet.Cells("PrintPageOrientation")

If you wish to fit the width and height of background with forgraound, you
might swap the height and width of the background page,
Sub SwapPageSize(myPage As Visio.Page)
Dim dblWidth As Double, dblHeight As Double
dblWidth = myPage.PageSheet.Cells("PageWidth")
dblHeight = myPage.PageSheet.Cells("PageHeight")
myPage.PageSheet.Cells("PageWidth") = dblHeight
myPage.PageSheet.Cells("PageHeight") = dblWidth
End Sub
 
J

JuneTheSecond

Or, to fit print orientation and page size at once,
Dim myBackPage As Visio.Page
Set myBackPage = ActivePage.BackPage
myBackPage.PageSheet.Cells("PrintPageOrientation") = _
ActivePage.PageSheet.Cells("PrintPageOrientation")
myBackPage.PageSheet.Cells("PageWidth") = _
ActivePage.PageSheet.Cells("PageWidth")
myBackPage.PageSheet.Cells("PageHeight") = _
ActivePage.PageSheet.Cells("PageHeight")
 
G

Garrett

I think ActivePage.PageSheet.Cells("PrintPageOrientation") is part of the
puzzle.

I guess what I am looking for is an event that I can trigger off of that
tells me when PrintPageOrientation has changed, so that I can change the
background using:

Visio.Application.ActivePage.BackPage = "My Background Page Name"

Thanks for your help!
 
J

JuneTheSecond

I am sorry for my misstake. The CellChabged event might be useful, like....

"ThisDocument"
Option Explicit
Private WithEvents myPage As Visio.Page
Private WithEvents myWin As Visio.Window
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Set myPage = ActivePage
Set myWin = ActiveWindow
End Sub
Private Sub Document_DocumentSaved(ByVal doc As IVDocument)
Set myPage = ActivePage
Set myWin = ActiveWindow
End Sub
Private Sub myPage_CellChanged(ByVal Cell As IVCell)
If Cell.Name = "PrintPageOrientation" Then
MsgBox Cell.Name & " of " & myPage.Name & " changed "
End If
End Sub
Private Sub myWin_WindowTurnedToPage(ByVal Window As IVWindow)
Set myPage = Window.Page
End Sub
 
J

JuneTheSecond

More practically, one of the proc. might be modified, for example,.....

Private Sub myPage_CellChanged(ByVal Cell As IVCell)
If Cell.Name = "PrintPageOrientation" Then
If Cell = 1 Then
ActivePage.BackPage = "Background-1"
Else
ActivePage.BackPage = "Background-2"
End If
End If
End Sub
 
D

David Parker

FYI .. My experience has shown that FormulaChanged is more efficient than
CellChanged.
They both should work, but using CellChanged slows down the response.
 
J

JuneTheSecond

Thank you David, it's fine. It can make events limit to the particular cell,
isn't it?
"ThisDocument"
Option Explicit
Private WithEvents myPage As Visio.Page
Private WithEvents myWin As Visio.Window
Private WithEvents myCell As Visio.Cell
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Set myPage = ActivePage
Set myWin = ActiveWindow
Set myCell = myPage.PageSheet.Cells("PrintPageOrientation")
End Sub
Private Sub Document_DocumentSaved(ByVal doc As IVDocument)
Set myPage = ActivePage
Set myWin = ActiveWindow
Set myCell = myPage.PageSheet.Cells("PrintPageOrientation")
End Sub
Private Sub myCell_FormulaChanged(ByVal Cell As IVCell)
If Cell = 1 Then
ActivePage.BackPage = "Background-1"
Else
ActivePage.BackPage = "Background-2"
End If
End Sub
Private Sub myWin_WindowTurnedToPage(ByVal Window As IVWindow)
Set myPage = Window.Page
Set myCell = myPage.PageSheet.Cells("PrintPageOrientation")
End Sub
 
J

JuneTheSecond

I made mistake again. Cellchanged events can also be limeited to the
particular cell.
Like,...

Private Sub myCell_CellChanged(ByVal Cell As IVCell)
If Cell = 1 Then
ActivePage.BackPage = "Background-1"
Else
ActivePage.BackPage = "Background-2"
End If
End Sub

, as same as,.....
Private Sub myCell_FormulaChanged(ByVal Cell As IVCell)
If Cell = 1 Then
ActivePage.BackPage = "Background-1"
Else
ActivePage.BackPage = "Background-2"
End If
End Sub

I shall have to study more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top