Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    I'm trying to write VBA code from MS Word 2003. This VBA code will be a small piece of my overall VBA code for this project. What I need is an example on how to code (in VBA) the previous page and the next page of a document currectly being accessed. For example for a three (3) page document, I want to click on the "Previous" button (user defined) to go to page #1, if I'm on page #2 or click on the "Next"button (user defined) go to page #3 (from page #2). Lastly, I want to go to the top of page #1, when I cick on "Top" button (user defined) from any page (page #1 or page #2).

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    A good way to get a feeling for the code you need is to record a macro. This may result in superfluous code or suboptimal code, but at least you'll have an idea of what to search for in the VBA help.

    To go to the next page:

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext

    As you might expect, you can also use wdGoToPrevious, wdGoToLast and wdGoToFirst.

  3. #3
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='765142' date='12-Mar-2009 22:05']A good way to get a feeling for the code you need is to record a macro. This may result in superfluous code or suboptimal code, but at least you'll have an idea of what to search for in the VBA help.

    To go to the next page:

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext

    As you might expect, you can also use wdGoToPrevious, wdGoToLast and wdGoToFirst.[/quote]

    Hans,

    Thanks ! ! ! I'll try this . . .

  4. #4
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    [quote name='LHooker' post='765253' date='13-Mar-2009 16:28']Hans,

    Thanks ! ! ! I'll try this . . .[/quote]


    Hans,

    That worked . . . Thanks ! ! ! How can I eliminate the printing of a command button ? It is used to avoid the problem I had with going to the next page of a document when a form is protected. Instead I used a few command buttons, but now I have the problem of command buttons printing on the document/form.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='LHooker' post='765656' date='16-Mar-2009 18:49'][/quote]
    You could format the command buttons as hidden text. Users can show hidden text on screen (this is an option in the View tab of Tools | Options) but hide it when printing (this is another option, in the Print tab of Tools | Options).

    An alternative would be to use custom toolbar buttons instead of command buttons.

  6. #6
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans,

    I tried the toolbar option and it worked, but now I can't figure out how to add the logic to turn off the protection of the form. I had the below code in the "Next" button. Remember, I can only get the dropdown arrow when the form is in protect mode.

    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    NoReset:=False
    Else
    ActiveDocument.Unprotect Password:=""
    End If
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The lines

    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    NoReset:=False
    Else
    ActiveDocument.Unprotect Password:=""
    End If

    toggle protection on and off. If you want to unprotect, go to the next page and reprotect, use

    ActiveDocument.Unprotect
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

  8. #8
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans,

    I'm now using your recommended customize toolbar (and it works). How can I add the code to an item in the customize toolbar ? I insert the code to show how my command button were working.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Select Tools | Customize...
    Activate the Commands tab.
    Make sure that your template or document is selected in the "Save in" dropdown at the bottom of the dialog.
    Select Macros in the list of Categories on the left.
    Select a macro in the list of macros on the right.
    Drag it to your custom toolbar and drop it there.
    Right-click the new toolbar button to modify the button's properties.
    Close the Customize dialog when you're done.

  10. #10
    New Lounger
    Join Date
    Dec 2008
    Location
    Mishawaka, Indiana, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans,

    That worked ! ! ! Thanks for your help ! ! !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •