View Single Post
 
Old 06-06-2015, 05:08 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
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