Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    Greetings,
    I am using AUTONUMLGL /e fields to number headings, and these are displaying and printing nicely, but when I want to get the field result with VBA, the example in the help works well for other fields, but not for AUTONUMLGL, nor for LISTNUM, the preferred replacement for AUTONUMLGL. Here's my code:

    Sub TryFields()
    If Selection.Fields.Count >= 1 Then
    MsgBox "Code = " & Selection.Fields(1).Code.Text & vbCr _
    & "Result = " & Selection.Fields(1).Result.Text & vbCr _
    & "Res2 = " & Selection
    End If
    End Sub

    Any ideas?
    Jim

  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: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    With LISTNUM, you can use the code in Microsoft Knowledge Base Article 315728 - HOW TO: Programmatically Obtain Paragraph Numbers Generated by a Style in Word 2000. With AUTONUMLGL, I don't see a way, but I'm not a numbering guru. (In fact, I like to number everything manually, except Outlines.)

  3. #3
    New Lounger
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    Thanks jscher for the reference to the MS article, but this refers to the outline numbering you get by clicking the "numbered paragraphs" button. These numbers refer to indentation level, not document outline level, so they don't affect the display in Document Map (or outline) view, so I use the AUTONUMLGL field. Also, the automatic numbering is difficult for inexperienced Word users to handle as they want to add or remove un-numbered paragraphs between numbered paragraphs. I know how to do it, but the people who will be making data files based on my template don't know how, so putting autonumbering fields in the headings is safer.

    Regards,
    Jim

  4. #4
    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: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    Ah, yes, but I tested the code with both AUTONUMLGL and LISTNUM fields, neither autonumbered. My results were as reported above.

  5. #5
    New Lounger
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    Sorry, I didn't understand your posting "my results were as reported above". Do you mean that you tried my code, or the code in the MS article? This time I'll attach a template that demonstrates the problem.

    Jim
    Attached Files Attached Files

  6. #6
    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: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    I tested Microsoft's code and it does retrieve the LISTNUM-type numbering but not the AUTONUMLGL-type numbering. I have no idea how to obtain the latter in code. There are some switches for the {REF} field that might be able to do it, but I'm not sure how you could use that in code...

  7. #7
    New Lounger
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    Thanks for your interest.
    Jim

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get Result for AUTONUMLGL field with VBA (Word 97, 2K, XP)

    The help on AutoNum, AutoNumLgl and AutoNumOut says they are old field functions that are only kept around for compatibility's sake, and that you should use ListNum fields instead.

    With ListNum fields, you can get the string (result) with .Range.ListFormat.ListString

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

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