Need to find a TA field using VBA

K

keith

Hello,
I need to find, select and copy the next Table of Authorities field using
VBA. I am working eith the example code shown below, but have been unable to
determine what will work in the find-text field to identify a TA field based
on the TA identifier, and not the contents of the field. Would appreciate
some help.

The code I have tried is in the help system, and is as follows.

With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
'.Execute FindText:="TA" ' this line found the TA letters, but also
found every other "ta" combination in the document.
.Execute FindText:="Microsoft"

End With

Thank you

keith
 
H

Helmut Weber

Hi Keith,

for lack of documents containing tables of authorities,
I can't test anything.

You may step through the fields collection, as a start.

Dim oFld As Field
For Each oFld In ActiveDocument.Fields
MsgBox oFld.Result
MsgBox oFld.Code
Next

In addition you may utilize the field type.
If oFld.type = wdFieldTOAEntry ' ?

But there is in addition a field of type wdFieldTOA.

I don't know and can't test which one is suitable.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

keith

Hello Helmut,

Thank you very much.
Those are helpful comments. I'll give them a try and may be on the way to a
soltion to this problem.
Keith
 
K

keith

Hello again Helmut.

I put your comments into a test subroutine, and they worked great. Thank
you very much. Below is the sub that produced the results I needed. I did
notice that the extracted code did not have the original formatting in the
msgbox (ie: italics) and will look at it again to see if the formatting is
there when it is placed in a document. It is important to have the original
formatting available.

Thanks again,

Keith


Below is the subroutine text

Public Sub TestSub1()

'from mvp Helmut Weber 7 5 2005

Dim oFld As Field
For Each oFld In ActiveDocument.Fields
'MsgBox oFld.Result
MsgBox oFld.Code
Next


For Each oFld In ActiveDocument.Fields
'MsgBox oFld.Result
If oFld.Type = wdFieldTOAEntry Then
MsgBox oFld.Code
End If
Next


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top