Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Feb 2001
    Location
    Georgia, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I find what page a Bookmark is on? (VBA Word 2000)

    I am trying to find what page a bookmark is on and save it to a string. What is the best way to acomplish this?

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Mike,

    This should work:

    Public Sub GetBMKPageNo()

    Dim rngBMK As Range
    Dim strBMK_PageNo As String

    Set rngBMK = ActiveDocument.Bookmarks("bmkTest").Range
    strBMK_PageNo = CStr(rngBMK.Information(wdActiveEndPageNumber))
    MsgBox strBMK_PageNo
    Set rngBMK = Nothing

    End Sub

    Gary

  3. #3
    New Lounger
    Join Date
    Feb 2001
    Location
    Georgia, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Thanks,
    This gave me the page number!

    Now, the page number format includes the appendix number( for instance "A-1" or "B-23").

    After looking at the help for the Information property, I didn't see how to get the appendix number (or other page number formatting) if included. How do I get that?

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Mike,

    That sure opens a can of worms! <g> - one thing you can be sure is, there is no built-in Information property to return that.

    It may be possible to do but the methods probably won't be pretty.

    More info first: how are you currently getting the appendix number and hyphen? - are these just hardtyped text ahead of the page number field, or are they generated as part of the page number field i.e. by using the "Include Chapter Number" feature in the Page Number Format dialog (and if the latter is the case, what is the name of the style that the chapter number is being generated by)?

    Gary

  5. #5
    New Lounger
    Join Date
    Feb 2001
    Location
    Georgia, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Yes the page number is generated with the "Include Chapter Number" feature. The heading level used may vary from document to document, however.

    I'll show you how I have been able to accomplish this in the past:

    ' First insert a cross reference to the bookmark that displays the page number.
    ' (MyRange is at the end of the document)
    MyRange.InsertCrossReference ReferenceType:="Bookmark", ReferenceKind:= _
    wdPageNumber, ReferenceItem:=CheckString, _
    InsertAsHyperlink:=True, IncludePosition:=False
    ' Cut the part I want
    MyRange.Start = MyRange.End - 1
    MyRange.Cut
    ' Open the document I want to paste it in
    Documents(NewDocument).Activate
    ' Finally PasteSpecial where the selection is at the moment
    Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
    wdInLine, DisplayAsIcon:=False

    My application is a little different this time and I'd like to be able to open the first document as read-only (or else I'll have to copy it) and this time I'm trying to place the page number into a text field in an Access database (which is why I'd like it as a string variable.)

    I'd hoped that I had overlooked an easy way to get the page number in the format I'd like.

    Thanks,
    mike c.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Hi Mike,

    The built-in Include Chapter Number feature is one I'm aware of, but not familiar with - this is 'cause it limits you to using the Heading1-9 styles as your numbered chapter heading styles, and all the Word templates I've worked on have used custom styles, rather than the Heading styles, to do numbering.
    However I've just done some playing around with this feature, using Heading styles, and it works well.

    Be that as it may, I'm getting stuck at the first comment in the code:

    <<First insert a cross reference to the bookmark that displays the page number>>

    - which bookmark is this to begin with, and why is there a bookmark displaying the page number? As far as I can see, the Include Chapter Number feature doesn't generate any bookmark in relation to the page number.

    Sorry 'cause I'm probably missing the obvious, but what is the connection between the bookmark and the page number as displayed using the footer page numbering field? The page number (including chapter number) is displaying in the footer - where is the bookmark that displays the page number? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Gary

  7. #7
    New Lounger
    Join Date
    Feb 2001
    Location
    Georgia, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    The confusion about the comment is entirely my fault.
    Maybe the comment should have said:

    "First insert a cross reference that displays the page number to the bookmark"

    Anyway, its the cross reference that shows the page number and it is cross referenced to a bookmark (it really doesn't matter where the bookmark is or what it displays.)

    This type of cross reference displays exactly what I want to be able to put into my database.

    By the way, I've got it working using this method and it appears to be much faster than using the bookmark.Information(wdActiveEndPageNumber) function. When I used the .Information function, I also kept getting the "Word is running out of memory, you will not be able to undo this action" error.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Have you tried wdActiveEndAdjustedPageNumber?

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Hi Mike,

    Having never used a cross-reference of this type (using the Word interface), I didn't understand what you were trying to do in code, until I tried creating a cross-reference to a bookmark, inserting reference to Page number (in Word) - that is very cool and works great! You can also get hold of a paragraph number that way which might have some applications.

    When I test-run your code, I'm getting a runtime error ("Command failed" - very descriptive!) on the last part that is attempting to do a PasteSpecial in the new document - any ideas as to what part of that statement might be causing the error?

    With regard to Howard's suggestion, ActiveEndAdjustedPageNumber does not give you the chapter number so it's not applicable in this situation.

    Regards,
    Gary

  10. #10
    New Lounger
    Join Date
    Feb 2001
    Location
    Georgia, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I find what page a Bookmark is on? (VBA Word 2000)

    Sorry its take me so long to respond. I didn't get that error so I'm not sure what makes yours get an error. I can only guess that maybe you don't have the NewDocument variable set to point to a separate document.

    I use the cross references all the time to point readers to information on another page.

    Thanks for all your ideas. Although I did not get it to work exactly like I'd like (mainly I have to open it Read/Write), my procedure does do what I want.

Posting Permissions

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