Discussion Locked

Word97 VBA question

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Is there a way, using VBA (or not?) to hide certain pages of a Word Document on opening? Maybe adding a password box or menu which would allow some users to view those pages?

Thanks

Craig

(PS - If you could, please CC me at mrmolio@hotmail.com - Thanks!)

6 replies

by sankulpune

Hello Craig,

Copy following code in a module
'--------
Sub PageHide()
Dim pNum As Integer
pNum = Trim(InputBox("Page No. To Hide : ", "Hide Page"))
ActiveWindow.View.ShowAll = False
ActiveWindow.View.ShowHiddenText = True
Application.ScreenUpdating = False
With Selection
.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pNum
If pNum = ActiveDocument.BuiltInDocumentProperties("Number of Pages") Then
.EndKey Unit:=wdStory, Extend:=wdExtend
Else .Extend
pNum = Trim(Str(Val(Trim(pNum)) + 1))
.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pNum
End If
.Font.Hidden = True
.Collapse wdCollapseStart
End With
ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub
Sub PageShow()
Dim pNum As Integer
pNum = Trim(InputBox("Page No. To Disply : ", "UnHide Page"))
ActiveWindow.View.ShowHiddenText = True
Application.ScreenUpdating = False
With Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pNum
If pNum = ActiveDocument.BuiltInDocumentProperties("Number of Pages") Then
'Last Page
.EndKey Unit:=wdStory, Extend:=wdExtend
Else
.Extend
pNum = Trim(Str(Val(Trim(pNum)) + 1))
.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=pNum
End If
.Font.Hidden = False
.Collapse wdCollapseStart
End With
ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub
'-----
Your feedback will be highly apprecited.

Please feel free to contact me if you need clarifications to help you to implement or try this code.

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

by sankulpune

Hello Craig,

1) Following code has been developed using WORD 97. It also works in WORD 2000.
2) It works with automatic page numbering of the document. Manual page numbering has not been tested.
3) It works in both Normal & Page-layout views.4) It can not prevent hidden pages being viewed using settings. Hence no security is possible.
5) To make password enabled security, 'Options' & 'Format > Font' menus
need to be disabled and needs more complex code. (Please inform if you are interested.)
6) Copy the code in a module in the Normal.doc (or any other template you use) to ensure that code is available to all documents that use this template.

Your feedback will be highly apprecited.

Please feel free to contact me if you need clarifications to help you to implement or try this code.

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

This discussion is closed to new replies.