Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2015, 05:08 AM
gmaxey gmaxey is offline Iterating through tables to find a bookmark Windows 7 32bit Iterating through tables to find a bookmark Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,600
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Graham,

Am I missing something? Why did you loop through the bookmarks?



Code:
Sub Macro1()
Dim wdApp As Object
Dim oDoc As Object
Dim oBM As Object
Dim bBM As Boolean
Dim oTable As Object
Const strBookmarkName As String = "MyTable"
    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err Then
      Set wdApp = CreateObject("Word.Application")
      Err.Clear
    End If
    Set wdDoc = wdApp.Documents.Open("Full path of document")
    Set oBM = oDoc.Bookmarks(strBookmarkName)
    If Err.Number <> 0 Then
      MsgBox ("Bookmark '" & strBookmarkName & "' not present in the document.")
    Else
      If oBM.Range.Information(12) Then
        Set oTable = oBM.Range.Tables(1)
        'do what you want with oTable e.g.
        oTable.Range.Select
      End If
    End If
lbl_Exit:
    Set oBM = Nothing
    Set oTable = Nothing
    Set oDoc = Nothing
    Set wdApp = Nothing
    Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 06-06-2015, 05:32 AM
gmayor's Avatar
gmayor gmayor is offline Iterating through tables to find a bookmark Windows 7 64bit Iterating through tables to find a bookmark Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

Quote:
Originally Posted by gmaxey View Post
Am I missing something? Why did you loop through the bookmarks?
If you are looking for a bookmark then surely it makes sense to look in the bookmark list for that bookmark, then ask which table it is associated with, rather than trawl through an unknown number of tables looking for a table that contains a bookmark?

Either would work, but I would contend that looking for the bookmark name directly is potentially faster.
__________________
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
Reply

Tags
bookmarks, vba word, word 2010



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterating through tables to find a bookmark Bookmark Not Showing Bookmark RegAudit Word 6 03-16-2015 11:08 PM
Iterating through tables to find a bookmark Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
vba to go to next bookmark megatronixs Word VBA 2 06-08-2014 09:53 PM
Iterating through tables to find a bookmark Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Iterating through tables to find a bookmark VBA to insert Bookmark rockwellsba Word VBA 2 05-31-2011 01:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:52 AM.


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