Dave
10-29-2007, 07:11 AM
This is XL VBA but essentially a Word problem. I've been using a variation of the following XL VBA code to control Word's pagination. I need Word's pagination turned on for other XL VBA code to work, but I want to return the user's Word pagination setting to its' original state following the completion of the other XL VBA code. My previous testing indicated that it worked as desired but now I find that when I go to ANY Word document that the background repagination checkbox is checked but the entire option is greyed out and no longer accessible (Open Word doc, tools/options/general to see background repagination). The following XL VBA code is similiar to what I'm using and is just designed to test this problem. My testing indicates that the pagination is indeed being changed but the option remains checked and greyed out whether pagination is on or off. Have I broke something? Perhaps setting pagination to false is actually removing it as an accessible option? Dave
ps. need "C\testit.doc" to test code
Sub PagTest()
Dim Wapp As Object, PagFlag As Boolean, Temp As String
On Error GoTo ErFix
'Open file
Set Wapp = CreateObject("Word.Application")
Temp = "c:\Testit.doc"
Wapp.documents.Open Filename:=Temp, ReadOnly:=True
MsgBox "Start Pagination is: " & Wapp.Options.Pagination
'change pagination
If Wapp.Options.Pagination = False Then
Wapp.Options.Pagination = True
PagFlag = True
Else
Wapp.Options.Pagination = False
PagFlag = False
End If
MsgBox "Changed Pagination is: " & Wapp.Options.Pagination
'return pagination to original setting
If PagFlag Then
Wapp.Options.Pagination = False
Else
Wapp.Options.Pagination = True
End If
MsgBox "Ending Pagination is: " & Wapp.Options.Pagination
Wapp.Quit
Set Wapp = Nothing
Exit Sub
ErFix:
On Error GoTo 0
If PagFlag Then
Wapp.Options.Pagination = False
Else
Wapp.Options.Pagination = True
End If
Wapp.Quit
Set Wapp = Nothing
End Sub
ps. need "C\testit.doc" to test code
Sub PagTest()
Dim Wapp As Object, PagFlag As Boolean, Temp As String
On Error GoTo ErFix
'Open file
Set Wapp = CreateObject("Word.Application")
Temp = "c:\Testit.doc"
Wapp.documents.Open Filename:=Temp, ReadOnly:=True
MsgBox "Start Pagination is: " & Wapp.Options.Pagination
'change pagination
If Wapp.Options.Pagination = False Then
Wapp.Options.Pagination = True
PagFlag = True
Else
Wapp.Options.Pagination = False
PagFlag = False
End If
MsgBox "Changed Pagination is: " & Wapp.Options.Pagination
'return pagination to original setting
If PagFlag Then
Wapp.Options.Pagination = False
Else
Wapp.Options.Pagination = True
End If
MsgBox "Ending Pagination is: " & Wapp.Options.Pagination
Wapp.Quit
Set Wapp = Nothing
Exit Sub
ErFix:
On Error GoTo 0
If PagFlag Then
Wapp.Options.Pagination = False
Else
Wapp.Options.Pagination = True
End If
Wapp.Quit
Set Wapp = Nothing
End Sub