Macro to go to the top of the next page of the document

D

DavidRocastle

Hi i would like to have a macro for Microsoft word whereby when clicked it
will take me to the top of the next page of the whole document. The problem
is, is that the document is protected.

I just need a macro on the top of the page whereby when clicked it will
bring me on to the top of the next page. This is done to check that the
correct data is entered at the top of the page!
 
J

Jean-Guy Marcil

DavidRocastle was telling us:
DavidRocastle nous racontait que :
Hi i would like to have a macro for Microsoft word whereby when
clicked it will take me to the top of the next page of the whole
document. The problem is, is that the document is protected.

I just need a macro on the top of the page whereby when clicked it
will bring me on to the top of the next page. This is done to check
that the correct data is entered at the top of the page!

The code would be:

With ActiveDocument
.Unprotect
Selection.GoTo wdGoToPage, wdGoToNext, 1
.Protect wdAllowOnlyFormFields
End With


But the cursor cannot be positioned on a page of a protected document that
does not contain editable fields. If the top of the next page (or the whole
page for that matter) does not contain formfields, the macro will not work
truly as expected, it will only take you to the next available field, if
none are available, it will place the cursor at the top of the document.
Or, if there are fields in the document, but not after the current page, the
macro will take you to the first field in the document.

If the document does not have any fields, the above macro will always place
the cursor on the first page and then display the second page, as soon as
the user clicks on that second page, the first page is displayed because
this is were the cursor is.

If you have formfields on your pages, then it will work, except that the
first available field on the page will be selected, which might not be at
the top of the page.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

DavidRocastle

Thanks for that Jean-Guy,

It worked perfect, could i ask you would you know how to change it that if
the document is protected do

..Unprotect
Selection.GoTo wdGoToPage, wdGoToNext, 1
.Protect wdAllowOnlyFormFields

if not go ahead and do
Selection.GoTo wdGoToPage, wdGoToNext, 1
.Protect wdAllowOnlyFormFields

Sorry about this, i don't have great experience in VBA coding. Many thanks
 
J

Jay Freedman

You check the document's .ProtectionType property, like this:

With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If

Selection.GoTo wdGoToPage, wdGoToNext, 1
.Protect wdAllowOnlyFormFields
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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