Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2012, 02:03 AM
dpb001 dpb001 is offline How do I read from a table located with a bookmark Windows Vista How do I read from a table located with a bookmark Office 2010 64bit
Novice
How do I read from a table located with a bookmark
 
Join Date: Mar 2012
Posts: 4
dpb001 is on a distinguished road
Default How do I read from a table located with a bookmark

I would lile to read / write to a version history table in a word 2010 document. I can locate the table with a bookmark, but can't see how I access the individual cells so I can write to or read from the table.



Code to locate table with a bookmark

Dim r as Range

If ActiveDocument.Bookmarks.Exists("Document_Revision _Table") Then
Set r = ActiveDocument.Bookmarks("Document_Revision_Table" ).Range
Selection.GoTo What:=wdGoToBookmark, Name:="Document_Revision_Table"
Else
MsgBox "Missing bookmark"
End If

As you can tell from this question I am a novice with vb so any explanatory text would be useful.

Much appreciated.
Reply With Quote
  #2  
Old 03-03-2012, 03:11 PM
macropod's Avatar
macropod macropod is offline How do I read from a table located with a bookmark Windows 7 64bit How do I read from a table located with a bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can read from / write to the table as follows:
Code:
Sub Demo()
Dim Rng As Range, BkMk as String
BkMk = "Document_Revision_Table"
With ActiveDocument
  If .Bookmarks.Exists(BkMk) Then
    If .Bookmarks(BkMk).Range.Tables.Count > 0 Then
      With .Bookmarks(BkMk).Range.Tables(1)
        'do something, eg:
        .Cell(1, 1).Range.Text = "Gothca!"
        Set Rng = .Cell(1, 1).Range
        Rng.End = Rng.End - 1
        MsgBox Rng.Text
      End With
    Else
      MsgBox "Missing table"
    End If
  Else
    MsgBox "Missing bookmark: " & BkMk
  End If
End With
End Sub
Note that there's no need to 'goto' or select anything.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 03-05-2012 at 04:03 PM. Reason: Code fix & enhancement
Reply With Quote
  #3  
Old 03-05-2012, 11:02 AM
dpb001 dpb001 is offline How do I read from a table located with a bookmark Windows Vista How do I read from a table located with a bookmark Office 2010 64bit
Novice
How do I read from a table located with a bookmark
 
Join Date: Mar 2012
Posts: 4
dpb001 is on a distinguished road
Default Read from table located with a bookmark

Thanks for the reply.

When I try running this code I get a run-time error 5941 “The requested member of the collection does not exist.”
At the line
If .Bookmarks("Document_Revision _Table").Range.Tables.Count > 0 Then

I believe this is due to Range.Tables not being part of the collection for bookmarks.

ActiveDocument contains “Bookmarks”
“Bookmark” contains “Range” not Bookmarks.

Or is there something wrong in my configuration?

Note a typo in the bookmark name – there is no space.
Reply With Quote
  #4  
Old 03-05-2012, 04:05 PM
macropod's Avatar
macropod macropod is offline How do I read from a table located with a bookmark Windows 7 64bit How do I read from a table located with a bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There was an error in the code, in that I'd copied the first instance of your bookmark name (Document_Revision _Table) without checking its validity. If you look at the bookmark name, you'll see a space in it. Boomark names can't have spaces. I've fixed the code and enhanced it slightly.

It's also worth noting that, for the code to work, you don't need to bookmark the whole table - a bookmark anywhere within it will do. I'd still be inclined to bookmark at least an end-of-row marker rather than something in one of the cells, though (especially not the cell you want to update).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-12-2012, 02:02 PM
dpb001 dpb001 is offline How do I read from a table located with a bookmark Windows Vista How do I read from a table located with a bookmark Office 2010 64bit
Novice
How do I read from a table located with a bookmark
 
Join Date: Mar 2012
Posts: 4
dpb001 is on a distinguished road
Default

Thanks for your help
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I read from a table located with a bookmark Auto-numbering non co-located Requirements in a document acheo Word 1 11-24-2011 05:24 PM
Error: The file may be corrupted, located on a server that is not responding, or read naeemeh Excel 2 11-20-2011 03:38 AM
How do I read from a table located with a bookmark VBA to insert Bookmark rockwellsba Word VBA 2 05-31-2011 01:07 AM
Bookmark Classification DrDoom Word 0 06-29-2010 07:08 AM
Bookmark to another document spqr Word 3 06-26-2009 04:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 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