[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Word VBA: How can I find out if a Bookmark is in a Table Cell?

Posted on 2005-05-14
5
Medium Priority
?
1,502 Views
Last Modified: 2008-02-01
I'm trying to modify a Word-document using COM. Multiple values have to be filled in in a table on multiple rows. I need to be sure that a Bookmark (defined by an advanced user in a Word-template) is in a table, so I can add rows if necessary to the table. How to find out that the bookmark is in a table? And if so, in which table, so I can extend the table?
0
Comment
Question by:Sjef Bosman
5 Comments
 
LVL 4

Accepted Solution

by:
_lv_ earned 500 total points
ID: 14002276

For Each bkm In Word.ActiveDocument.Bookmarks
   If bkm.Range.Information(wdWithInTable) = True Then
     ...
   End If
Next

Or explicitly:
If Word.ActiveDocument.Bookmarks("knowvn_bookmark").Range.Information(wdWithInTable) = True Then ...

(look at the 'Information' property of the 'Range' object. It returns many useful information)
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 14002676
That's a big step into the right direction! Now the second part: "And if so, in which table, so I can extend the table?" Do I have to go through all tables, select them and ask whether the bookmark is within the selection?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
ID: 14002990
No, you can use the tables collection in the bookmark's range.
Hopefully the bookmark is in a table:

Dim bmk As Bookmark
Dim rng As Range
Dim tbl As Table
Set bmk = ActiveDocument.Bookmarks("bmkMyBookmark")
Set rng = bmk.Range
If rng.Tables.Count = 1 Then
    Set tbl = rng.Tables(1)
Else
    MsgBox "Mum, I've got a problem"
End If
0
 

Expert Comment

by:yoss613
ID: 14006657
You may add to each Table in your template a bookmark with prefix like "TBL_MyBM" by select all the table when adding the bm.
the user will open the template and add bm to one of the tables, Now you check all the bm in the document and if the bm is with prefix TBL_ you have all the range of the table and you can search if the user add a bm to it.

For Each bm in doc.bookMarks
if Left(bm,4)="TBL_" Then CheckBm(bm.Name)
Next

sub CheckBm(bm)
Set oRange = Doc.BookMarks(bm).Range
i=oRange.BookMarks.count
If i>0 then
'the user entered a bookmark



Bye,
Yoss

0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 14008824
Hi all,

Working through the muddy waters of MSDN on Word and VBA hasn't been easy, but I found the rest of the clues I was looking for. And I suppose I can find the rest there as well. If not, I'll be back ;)

Yoss: I'm sorry, the whole point of my question, but maybe I wasn't clear enough, is that I do not make the templates. The advanced user is a user of my application, who creates a template for a document. This template has to contain bookmarks to indicate places where data from my application has to be inserted. I don't want to rely upon the advanced user to include a special bookmark, just for the sake of the application, if it's not necessary at all.

Thanks all!

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question