To all,
I am using VISIO 2007. I copied VB code from the article called "Fit all Pages to Window in a VISIO Document". When I compiled it, I received the error dialog box with the message "Compiler Error: Syntax Error".
The statement that was highlighted was:
Private Function m_uiGetActiveDrawingWindow() As Visio.Window
I am hoping that somebody might be able to help this NEWBIE!
Here is the code that I copied:
Option Explicit
Const MESSAGE_CAPTION$ = "Fit All Pages"
Public Sub SetAllPagesToFit()
'// Get the active window, if it is a drawing window:
Dim win As Visio.Window
Set win = m_uiGetActiveDrawingWindow()
If (win Is Nothing) Then Exit Sub
Dim doc As Visio.Document
Dim pg As Visio.Page, pgOrig As Visio.Page
Set pgOrig = win.Page
Set doc = pgOrig.Document
'// Fit each window. -1 is the zoom value for
'// fit-to-page:
For Each pg In doc.Pages
win.Page = pg
win.Zoom = -1
Next
'// Return the window to the original page:
win.Page = pgOrig
End Sub
Private Function m_uiGetActiveDrawingWindow() As Visio.Window
'// Checks the active window to see if it is
'// a drawing window. If not, an error is presented
'// to the user.
Set m_uiGetActiveDrawingWindow = Nothing
Dim win As Visio.Window
If (Visio.ActiveWindow Is Nothing) Then
Call MsgBox("This code requires an active drawing " & _
"window to function properly!", , _
MESSAGE_CAPTION$)
Exit Function
End If
Set win = Visio.ActiveWindow
If (win.Type <> Visio.VisWinTypes.visDrawing) Then
Call MsgBox("The active window is not a drawing " & _
"window. Please make sure the active " & _
"window is a drawing window!", _<br /> , MESSAGE_CAPTION$)
Exit Function
End If
Set m_uiGetActiveDrawingWindow = win
End Function
A major problem is the the VB you have is a different language to the VBA required for macros.
Another issue may be, that the code was posted on a webside and got somehow corrupted:
For example, I don't think that "_<br />" or "&" are VB or VBA.
The only issue is the html fragments that you have copied in the code. So thats the <br />, &, <, >. And as Paul pointed out about language differences, VBA is a subset of VB, so whilst very similar there can be a few minor differences.
A "repaired" version for VBA (VB may be a little different as mentioned by Paul and Andy)
Option Explicit
Const MESSAGE_CAPTION$ = "Fit All Pages"
Public Sub SetAllPagesToFit()
'// Get the active window, if it is a drawing window:
Dim win As Visio.Window
Set win = m_uiGetActiveDrawingWindow()
If (win Is Nothing) Then Exit Sub
Dim doc As Visio.Document
Dim pg As Visio.Page, pgOrig As Visio.Page
Set pgOrig = win.Page
Set doc = pgOrig.Document
'// Fit each window. -1 is the zoom value for
'// fit-to-page:
For Each pg In doc.Pages
win.Page = pg
win.Zoom = -1
Next
'// Return the window to the original page:
win.Page = pgOrig
End Sub
Private Function m_uiGetActiveDrawingWindow() As Visio.Window
'// Checks the active window to see if it is
'// a drawing window. If not, an error is presented
'// to the user.
Set m_uiGetActiveDrawingWindow = Nothing
Dim win As Visio.Window
If (Visio.ActiveWindow Is Nothing) Then
Call MsgBox("This code requires an active drawing " & _
"window to function properly!", , _
MESSAGE_CAPTION$)
Exit Function
End If
Set win = Visio.ActiveWindow
If (win.Type <> Visio.VisWinTypes.visDrawing) Then
Call MsgBox("The active window is not a drawing " & _
"window. Please make sure the active " & _
"window is a drawing window!", , MESSAGE_CAPTION$)
Exit Function
End If
Set m_uiGetActiveDrawingWindow = win
End Function
Hope I didn't forget sth.
If I were a betting man, I'd say this article is the source of the code, Fit All Pages to Window in a Visio Document, http://www.visguy.com/2011/04/13/fit-all-pages-to-window-in-a-visio-document/
It is VBA code -- according to the article. :)
Wapperdude
You are correct. That is exactly where I got the code. I since was able to fix the code. The reference to MSGBOX was wrong. So, it was highlight the previous statement of course.