J
JGM
Hi all,
I wrote the following code to scan fields in a target document, looking for
a DATABASE field that matches one in a source document. If the field is
found, then I check for the presence of a second field next to it, a PRINT
field so that I can insert one if necessary. The goal is to automate the
insertion of PRINT fields that will allow me to automatically generates PDF
links after I convert the Word document.
The problem:
The target document can have anywhere from 300 to 1000 fields, if the one I
need is the the 12th, it flies, OTH, if it is the 958th, then it takes a
quite a long time to find it... I tried two versions:
'_______________________________________
For i = 1 To TargetDoc.Fields.Count
If InStr(TargetDoc.Fields(i).Code.Text, FullTextKey) <> 0 Then
TargetTextFound = True
Exit For
End If
Application.StatusBar = CLng((100 * _
i) / TargetDoc.Fields.Count) & " % des fiches examinées..."
Next i
'_______________________________________
or
'_______________________________________
Dim myTargetField As Field
For Each myTargetField In TargetDoc.Fields
i = myTargetField.Index
If InStr(myTargetField.Code.Text, FullTextKey) <> 0 Then
TargetTextFound = True
Exit For
End If
Application.StatusBar = CLng((100 * _
i) / TargetDoc.Fields.Count) & " % des fiches examinées..."
Next myTargetField
'_______________________________________
Is it the best Word VBA can do? Or is there another way to go tjhrough the
field collection?
Is it advisable to set up the target document so that all field codes are
toggled on, and then use the Find method instead?
TIA
I wrote the following code to scan fields in a target document, looking for
a DATABASE field that matches one in a source document. If the field is
found, then I check for the presence of a second field next to it, a PRINT
field so that I can insert one if necessary. The goal is to automate the
insertion of PRINT fields that will allow me to automatically generates PDF
links after I convert the Word document.
The problem:
The target document can have anywhere from 300 to 1000 fields, if the one I
need is the the 12th, it flies, OTH, if it is the 958th, then it takes a
quite a long time to find it... I tried two versions:
'_______________________________________
For i = 1 To TargetDoc.Fields.Count
If InStr(TargetDoc.Fields(i).Code.Text, FullTextKey) <> 0 Then
TargetTextFound = True
Exit For
End If
Application.StatusBar = CLng((100 * _
i) / TargetDoc.Fields.Count) & " % des fiches examinées..."
Next i
'_______________________________________
or
'_______________________________________
Dim myTargetField As Field
For Each myTargetField In TargetDoc.Fields
i = myTargetField.Index
If InStr(myTargetField.Code.Text, FullTextKey) <> 0 Then
TargetTextFound = True
Exit For
End If
Application.StatusBar = CLng((100 * _
i) / TargetDoc.Fields.Count) & " % des fiches examinées..."
Next myTargetField
'_______________________________________
Is it the best Word VBA can do? Or is there another way to go tjhrough the
field collection?
Is it advisable to set up the target document so that all field codes are
toggled on, and then use the Find method instead?
TIA