Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2015, 12:59 PM
Hdata Hdata is offline List bookmark names in word doc Windows 7 32bit List bookmark names in word doc Office 2010 32bit
Novice
List bookmark names in word doc
 
Join Date: Jan 2014
Posts: 26
Hdata is on a distinguished road
Default List bookmark names in word doc

I have a macro that lists bookmark names at the end of the doc in alphabetical order of bookmark name. Very cool. However, I would like to change the list to so the first bookmark name by location in doc is listed first, and so on to last bm name. Also gives the number of bookmarks.



Also, I attached a word file with brief list of bookmark names.

Code:
 
Sub BMNames()
   ' Dim abookmark As Bookmark
    Dim abookmark As Variant
    Dim i As Integer
   ' Dim aMarks() As Integer
    Dim aMarks() As Variant
 
    Selection.EndKey Unit:=wdStory
    Set abookmark = ActiveDocument.Bookmarks
    If ActiveDocument.Bookmarks.Count >= 1 Then
    ReDim aMarks(ActiveDocument.Bookmarks.Count - 1)
    i = 0
    For Each abookmark In ActiveDocument.Bookmarks
        aMarks(i) = abookmark.Name
        Selection.TypeText Text:=abookmark.Name
        Selection.TypeParagraph
        i = i + 1
    Next abookmark
End If
    MsgBox "The active document contains " & _
    ActiveDocument.Bookmarks.Count & " bookmarks."
End Sub
Attached Files
File Type: docx BookMarkNamesTest1.docx (65.1 KB, 8 views)
Reply With Quote
  #2  
Old 04-11-2015, 12:05 AM
gmayor's Avatar
gmayor gmayor is offline List bookmark names in word doc Windows 7 64bit List bookmark names in word doc Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will do that, however if you are working with bookmarks, you should find http://www.gmayor.com/BookmarkandVariableEditor.htm useful:

Code:
Sub BMNames()
Dim oBM As Bookmark
Dim oRng As Range
Dim strList As String
    strList = ""
    If ActiveDocument.Bookmarks.Count > 0 Then
        For Each oBM In ActiveDocument.Range.Bookmarks
            strList = strList & oBM.name & vbCr
        Next oBM
        ActiveDocument.Range.InsertParagraphAfter
        Set oRng = ActiveDocument.Range
        oRng.Collapse 0

        oRng.Text = strList & vbCr & "The active document contains " & _
                    ActiveDocument.Bookmarks.Count & " bookmarks."
    Else
        MsgBox "There are no bookmarks in the document"
    End If
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-11-2015, 05:03 AM
Hdata Hdata is offline List bookmark names in word doc Windows 7 32bit List bookmark names in word doc Office 2010 32bit
Novice
List bookmark names in word doc
 
Join Date: Jan 2014
Posts: 26
Hdata is on a distinguished road
Default

Thanks Graham, works great. Hope you have a excellent day.

Hdata
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
List bookmark names in word doc Bookmark applied to drop-down list doesn't do the job thecreaser Word 5 04-11-2013 04:21 AM
Right Click menu list names jimbassett Word 0 02-25-2013 02:39 PM
List bookmark names in word doc auto insert names from list for printing andreipopa2k Word 1 12-09-2011 01:51 PM
List bookmark names in word doc Using a list of names in credits effect Pemberton PowerPoint 4 08-17-2010 02:10 AM
List bookmark names in word doc Random names from a given list professor snape Excel 1 06-06-2009 09:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft