Results 1 to 10 of 10
  1. #1
    Lounger
    Join Date
    Jun 2009
    Location
    London, UK
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I have a Word template with multi-sections. The page numbering starts from the fourth page of the template (after the front page and ToCs), but I need it to begin at number 1 from here (rather than number 4). However, it often reverts to number 4, and/or re-numbers itself from number 1 at the start of a new section.

    I was wondering if I could add a button of some sort that a user can press just before report publish, which goes through the document and fixes the Word numbering so it correctly begins at number 1 from page 4, and runs consecutively throughout the whole report -- is this possible in Word 2003.

    The template in question is attached in case of use.

    Many thanks,
    Sam
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here is a macro you might be able to use. Make sure that you store it in a standard module in the template:

    Code:
    Sub Renumber()
      Dim i As Integer
      With ActiveDocument.Sections(4).Headers(wdHeaderFooterPrimary).PageNumbers
    	.RestartNumberingAtSection = True
    	.StartingNumber = 1
      End With
      For i = 5 To ActiveDocument.Sections.Count
    	With ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers
    	  .RestartNumberingAtSection = False
    	End With
      Next i
    End Sub
    Using Tools | Customize you can assign it to a custom toolbar button and/or menu item, and by clicking Keyboard... in the Customize dialog, you can assign it to a custom keyboard shortcut. Make sure that changes will be saved in the template, not in your Normal.dot template.

  3. #3
    Lounger
    Join Date
    Jun 2009
    Location
    London, UK
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for your help again Hans.

    Forgive me for my ignorance, but I haven't inserted code into a Word template before so I wanted to check that I am doing it correctly (as I'm not sure what standard module means).

    I click Alt+F11 to bring up the VBE. On the left-hand side on the Windows Explorer-like tree, I click the relevant "TemplateProject (Template name)", under which is "Microsoft Word Objects", under which is "ThisDocument" -- if I double-click ThisDocument, a code box appears on the right -- is this what you mean by standard module?

    Also, the code box has a drop-down menu with either "(General)" or "(Document)" to choose from -- which one should be used? (There is another drop-down menu but this only includes "Declarations".)

    Many thanks,
    Sam

    [quote name='HansV' post='790823' date='26-Aug-2009 14:33']Here is a macro you might be able to use. Make sure that you store it in a standard module in the template:

    Code:
    Sub Renumber()
      Dim i As Integer
      With ActiveDocument.Sections(4).Headers(wdHeaderFooterPrimary).PageNumbers
    	.RestartNumberingAtSection = True
    	.StartingNumber = 1
      End With
      For i = 5 To ActiveDocument.Sections.Count
    	With ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).PageNumbers
    	  .RestartNumberingAtSection = False
    	End With
      Next i
    End Sub
    Using Tools | Customize you can assign it to a custom toolbar button and/or menu item, and by clicking Keyboard... in the Customize dialog, you can assign it to a custom keyboard shortcut. Make sure that changes will be saved in the template, not in your Normal.dot template.[/quote]

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You should *not* insert this code in ThisDocument. Instead, click once on your template in the treeview, then select Insert | Module. This creates a standard code module (ThisDocument is a very special one). Copy the code into the module that you created.

  5. #5
    Lounger
    Join Date
    Jun 2009
    Location
    London, UK
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll give it a go now.

    [quote name='HansV' post='791002' date='27-Aug-2009 12:34']You should *not* insert this code in ThisDocument. Instead, click once on your template in the treeview, then select Insert | Module. This creates a standard code module (ThisDocument is a very special one). Copy the code into the module that you created.[/quote]

  6. #6
    Lounger
    Join Date
    Jun 2009
    Location
    London, UK
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans -- the macro seems to be working perfectly.

    When I come to assign a custom button to the macro, I have created a new toolbar and added the new button to the toolbar. However, I only seem to have access to a very limited choice of images for the buttons. Is this the only choice of buttons I have -- am I able to assign images from other sources? I want to assign something as simple as a number 1 to the renumbering macro button.

    I also remember a really nice button that Hans used for an autotext button to insert a landscape page -- where can I get access to this image and ones like it?

    Many thanks,
    Sam

    [quote name='HansV' post='791002' date='27-Aug-2009 12:34']You should *not* insert this code in ThisDocument. Instead, click once on your template in the treeview, then select Insert | Module. This creates a standard code module (ThisDocument is a very special one). Copy the code into the module that you created.[/quote]

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can edit and draw button images - while in Customize mode, right-click a button and select Edit Button Image from the popup menu.
    The editor is rather primitive, but with a bit of work you can create nice images.

    Another possibility is to copy a graphic to the clipboard in any application, then in Word, right-click a button in Customize mode and select Paste Button Image from the popup menu. Keep in mind that the picture will be resized to 16 by 16 pixels.

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    [quote name='Sam577' post='791005' date='27-Aug-2009 13:13']Thanks Hans -- the macro seems to be working perfectly.

    When I come to assign a custom button to the macro, I have created a new toolbar and added the new button to the toolbar. However, I only seem to have access to a very limited choice of images for the buttons. Is this the only choice of buttons I have -- am I able to assign images from other sources? I want to assign something as simple as a number 1 to the renumbering macro button.

    I also remember a really nice button that Hans used for an autotext button to insert a landscape page -- where can I get access to this image and ones like it?

    Many thanks,
    Sam[/quote]
    Another easy way to get ready-made button images is to go to Tools > Customize and look through the list of existing Word commands - you can often find an existing button image for some obscure command, which can be used as-is or modified for your purposes. If you find a command with an image that you like, just temporarily drag that command onto any toolbar, then right-click on it and select "Copy Button Image" - you can then paste that button image into your custom toolbar item.

    Gary

  9. #9
    Lounger
    Join Date
    Jun 2009
    Location
    London, UK
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for all that -- I have been able to adapt an existing button from your instructions and attach it to the macro.

    When I first put the macro in as instructed, it worked perfectly, but when I opened the template up the next day, I found it was no longer working, coming up with "compile error, syntax error". I'm sure I saved it in the correct template rather than Normal, but can't work out what's gone wrong since the first day. Also, is it possible to certify/authenticate the renumbering macro to avoid the warning alerts?

    Also, in the attached, I can't get rid of the Same as Previous setting that appears when new sections are inserted in the headers and footers, even though there is no such setting in the previous headers and footers. I had this problem before and was able to fix it, but this time I can't. Is there another place where this setting is made that I don't know about?

    Many thanks,
    Sam
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    For some reason, some of the spaces in the macro were non-breaking spaces instead of ordinary spaces; this caused the syntax errors.

    You could use another macro (and toolbar button) to insert a new section and turn off "same as previous" for the header and footer:

    Code:
    Sub InsertNewSection()
      Selection.InsertBreak Type:=wdSectionBreakNextPage
      With Selection.Sections(1)
    	.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
    	.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
      End With
    End Sub
    See attached version.

    See the links in Digital Signatures. Commercial certificates are not cheap!
    Attached Files Attached Files

Posting Permissions

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