In my document footer I have a table that consists of 1 row and 3 columns.
What I would like to do is take the second word in column 1 and save it as
Word1 and take the second word in column 2 and save it as Word2. Then in my
document have bookmark ‘bknbr’ = Word1 and bookmark ‘bkRev’ = Word2.
Below you will find some code that should do what you want. If your table is
not in the primary footer in section 1, you need to adjust the code.
Dim strWord1 As String
Dim strWord2 As String
Dim oBkRange As Range
Dim strBk1 As String
Dim strBk2 As String
'Define bookmark names
strBk1 = "bknbr"
strBk2 = "bkRev"
'Find words in footer table to use as bookmark text
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1)
'Trim removes trailing spaces
strWord1 = Trim(.Cell(1, 1).Range.Words(2).Text)
strWord2 = Trim(.Cell(1, 2).Range.Words(2).Text)
End With
'Update bookmark text
'Bookmarks must be added again
With ActiveDocument
'Update first bookmark
Set oBkRange = .Bookmarks(strBk1).Range
oBkRange.Text = strWord1
'Add bookmark again
.Bookmarks.Add Name:=strBk1, Range:=oBkRange
'Update second bookmark
Set oBkRange = .Bookmarks("bkRev").Range
oBkRange.Text = strWord2
'Add bookmark again
.Bookmarks.Add Name:=strBk2, Range:=oBkRange
End With
Set oBkRange = Nothing

Signature
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
> In my document footer I have a table that consists of 1 row and 3 columns.
> What I would like to do is take the second word in column 1 and save it as
> Word1 and take the second word in column 2 and save it as Word2. Then in my
> document have bookmark ‘bknbr’ = Word1 and bookmark ‘bkRev’ = Word2.
Fuzzhead - 07 Jul 2007 23:52 GMT
Lene,
I tried the macro but it did not work. It is not seeing the text in the
table. I'm not sure what you mean by the table not in the primary footer in
section1, but the table is the only thing in the footer which is in all the
pages of the document.
Fuzzhead
> Below you will find some code that should do what you want. If your table is
> not in the primary footer in section 1, you need to adjust the code.
[quoted text clipped - 38 lines]
> > Word1 and take the second word in column 2 and save it as Word2. Then in my
> > document have bookmark ‘bknbr’ = Word1 and bookmark ‘bkRev’ = Word2.
Fuzzhead - 08 Jul 2007 00:02 GMT
Lene,
I got to work. I did not know that I had to count hard returns, tabs and
spaces. Once I counted for them it worked.
Thank you for your help.
Fuzzhead
> Below you will find some code that should do what you want. If your table is
> not in the primary footer in section 1, you need to adjust the code.
[quoted text clipped - 38 lines]
> > Word1 and take the second word in column 2 and save it as Word2. Then in my
> > document have bookmark ‘bknbr’ = Word1 and bookmark ‘bkRev’ = Word2.
Lene Fredborg - 08 Jul 2007 00:30 GMT
I am glad you got it to work.
For information about sections, see:
http://word.mvps.org/faqs/formatting/WorkWithSections.htm
Each section can have three different kinds of headers and footers. For more
details, see:
http://sbarnhill.mvps.org/WordFAQs/HeaderFooter.htm

Signature
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
> Lene,
>
[quoted text clipped - 46 lines]
> > > Word1 and take the second word in column 2 and save it as Word2. Then in my
> > > document have bookmark ‘bknbr’ = Word1 and bookmark ‘bkRev’ = Word2.