johnske
10-08-2004, 03:51 PM
Hi, the basis of the problem is this: I have the following code that I want to run the very first time the Word doc is opened, but not after that.
However I might very well change my mind about the page setup later on, so I'll include the public sub SetupPage that can be run manually to trigger the Open event later on.
I can do this in XL by writing somethng in an obscure cell after the
Document_Open event, but what is "an obscure cell that I can write something in" in Word? (the missing commands are written in as comments) :bink:
EDITED since 1st post:
Private Sub Document_Open()
Dim Answer As VbMsgBoxResult
'If (there is a note this sub has been run) Then Exit Sub
Answer = MsgBox("Your preferred setup?", vbYesNo)
'Leave a note indicating this sub has been run
If Answer = vbNo Then Exit Sub
With ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.6)
.BottomMargin = InchesToPoints(0.97)
.LeftMargin = InchesToPoints(0.6)
.RightMargin = InchesToPoints(0.6)
.PageWidth = InchesToPoints(8.27)
.PageHeight = InchesToPoints(11.69)
End With
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
Selection.Font.Name = "Verdana"
ActiveDocument.Save
MsgBox ("All done - And saved! :o)")
End Sub
Sub SetupPage()
'Remove the note indicating Document_Open has been run
Document_Open
End Sub
However I might very well change my mind about the page setup later on, so I'll include the public sub SetupPage that can be run manually to trigger the Open event later on.
I can do this in XL by writing somethng in an obscure cell after the
Document_Open event, but what is "an obscure cell that I can write something in" in Word? (the missing commands are written in as comments) :bink:
EDITED since 1st post:
Private Sub Document_Open()
Dim Answer As VbMsgBoxResult
'If (there is a note this sub has been run) Then Exit Sub
Answer = MsgBox("Your preferred setup?", vbYesNo)
'Leave a note indicating this sub has been run
If Answer = vbNo Then Exit Sub
With ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.6)
.BottomMargin = InchesToPoints(0.97)
.LeftMargin = InchesToPoints(0.6)
.RightMargin = InchesToPoints(0.6)
.PageWidth = InchesToPoints(8.27)
.PageHeight = InchesToPoints(11.69)
End With
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
Selection.Font.Name = "Verdana"
ActiveDocument.Save
MsgBox ("All done - And saved! :o)")
End Sub
Sub SetupPage()
'Remove the note indicating Document_Open has been run
Document_Open
End Sub