Results 1 to 15 of 15
  1. #1
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    macro compatibility 97 --> XP (XP)

    Hello, everyone! I had a template that was working fine in Word 97. My hard drive died and when they gave me a new one, they installed Office XP on it. Now part of my my template won't work. This macro is supposed to update the page number in the header and is called when the user picks Save or SaveAs. (All of the other macros still work fine.) Can anybody tell me whjat is wrong? <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16> Are there known issues with macro compatibility not being as clean as we'd expect?

    I am running Word XP with no service packs on NT 4.0 SP6.

    Thank you for helping!

    This is the macro---I got it from one of the Word forums (maybe this one):

    <pre>Sub UpdateNumPages()
    'This sub updates the NumPages field in the header, and no other fields.
    Dim oSec As Section
    Dim oFld As Field
    For Each oSec In ActiveDocument.Sections
    If oSec.Headers(wdHeaderFooterPrimary).Exists Then
    For Each oFld In oSec.Headers(wdHeaderFooterPrimary).Range.Fields
    If oFld.Type = wdFieldNumPages Then
    oFld.Locked = False
    oFld.Update
    oFld.Locked = True
    ' if there may be more than one NumPages field,
    ' remove the next line
    Exit For
    End If
    Next oFld
    End If
    Next oSec
    End Sub</pre>

    This is how this is called---

    <pre>Public Sub FileSaveAs()
    UpdateNumPages
    Dialogs(wdDialogFileSaveAs).Show
    errorHandler:
    If Err = 4198 Then MsgBox "The document was not saved properly. Please try again."
    End Sub</pre>

    Edited: <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags added around the code to make it more readable. -Mod.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: macro compatibility 97 --> XP (XP)

    The code looks fine, although it does a very limited thing. Is it simply failing to work, or are you getting an error message? Is it possible that there are no NUMPAGES fields in your header? If you press Alt+F9 to toggle on field codes, what exactly do you see?

    Incidentally, the Page X of Y bug was finally fixed in Office XP (perhaps it was the original version, perhaps SP-1), so you might not need to lock this field any more (and therefore, unlock, update, and re-lock it). Wouldn't that be a great solution!

  3. #3
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Thanks, jscher2000. The code is simply failing to run, not giving any error messages or help of any kind. Yes, it is very limited. My header has other fields that are handled through dialog boxes. There is only one header in the file, then a short protected Section 1 and an unprotected Section 2. This is just supposed to update the "Page x of y" on saving in case the user entered enough text in the unprotected section to change the page count.

    I've only had XP a couple of days and was not aware that the bug had been addressed. I'll check into that and see if it helps.

    Thanks,
    May

  4. #4
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    On jscher2000's advice, I commented out the page number update in my template and unlocked the "Page x of y" in my header. When I created a two-page document, the page numbers in the header updated and saved correctly. However, when I reopened the document to revise it and deleted all but 2 lines of text, my then-single-page document still read "Page 1 of 2" after I saved it. Any ideas, anyone??? <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> I have another 40 or so templates that use this same set-up, and this is the only thing holding up my issue.

    Thanks,
    May

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: macro compatibility 97 --> XP (XP)

    The header fields will update if you use Print or Print Preview. You also could try to update them using code. But I wonder: even if you change the document and save it with an incorrect page count, does it matter if the count will be corrected at print-time?

  6. #6
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Thanks for the suggestion, but that didn't work. Everything stayed "Page 1 of 1, " even on the printout. I also tried switching from page layout view to normal and back, but also with no luck.

    I'd suspect a corrupt document, but the same thing (the original problem of my macro not functioning; I've only tested the other ideas in the first template) happens in a different template now that I'm running XP.

    May

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: macro compatibility 97 --> XP (XP)

    Please post a sample document as it would be created with File>New. Thanks.

  8. #8
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Here is a document based on a stripped-down template. The header contains a PAGEREF and two NUMPAGES fields. The right-most NUMPAGES is the one that used to work in Word 97; the other fields are ones I added in XP. On my computer, the NUMPAGES do not update and the PAGEREF does, but it makes my Page Down key go haywire.

    I'd appreciate any feedback. I'm most interested in how this works/fails for those of you using XP and 97--I have to support both.

    Thanks,
    May
    Attached Files Attached Files

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

    Re: macro compatibility 97 --> XP (XP)

    There is little to investigate, since your document is protected by a password. This means for instance that we can't open the page header.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: macro compatibility 97 --> XP (XP)

    The NUMPAGES fields do not show the correct page count in Word 2000. Due to the document protection, I can't investigate them.

    If I open and re-save the document in StarOffice to remove the protection, then the NUMPAGES fields seem to behave normally.

  11. #11
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Oops! The password is "hello".

    May

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

    Re: macro compatibility 97 --> XP (XP)

    The NUMPAGES fields in your document refuse to update whatever I do with them. I deleted them and inserted a new one and that works fine. You mentioned in another thread that you have other problems with Word 2002; maybe your installation of Word 2002 is damaged. I don't think this NUMPAGES problem has anything to do with the comaptibility settings of the document. I have attached the document with the new NUMPAGES field. It's protected again with the same password.
    Attached Files Attached Files

  13. #13
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Hans,

    THANK YOU for the attachment with the number fixed, and I apologize for being so long in responding. My boss decided that I needed a different computer, and I delayed in hopes of being able to post a complete summary.

    My new computer is running Windows 2000 with Office XP. No service packs on XP yet, though that will happen this morning. Right now on my new box, if I delete and reinsert my existing Page X of Y, it is still broken and the PAGEREF still updates but with the PageDown key looping endlessly. But I copied the Page X of Y from your document, put it in my template, and it worked fine! I've got to strip out my fields that didn't work and then verify that someone on another box (NT 4.0 / Word 97) can use the template. So everything isn't fixed here, but thanks to Hans <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> it looks like I have a temporary work-around and will be able to issue files while we try to get to the root cause.

    Many thanks!!!

    May

  14. #14
    New Lounger
    Join Date
    Apr 2003
    Location
    South Carolina, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro compatibility 97 --> XP (XP)

    Well, I spoke too soon. Hans' fix works when I create a file--page numbers update properly. But if I create and save a two-page file, open it and cut it to one page, the numbers don't update. I'll post back after we put on the Office service packs and look at things running in the background.

    May

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

    Re: macro compatibility 97 --> XP (XP)

    Strange. If I cut the document to one page, the page count doesn't update instantaneously, but it does update if I print or print preview, or activate the page header.

Posting Permissions

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