How to test absence of includetext fields in document?

F

fokrogh

I have written a event macro that adjust tables and removes tabulators
in the word document.

How can i make the macro check the absence of any "includetext" fields
in the document before the macro adjust tables and removes tabulators?

Regards

Frank
___________________________

Private Sub Document_Close()

Application.ScreenUpdating = False

Selection.HomeKey Unit:=wdStory
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
Next aTable

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = vbTab
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True

End Sub
 
J

Jay Freedman

Add the following function to your project; the demo macro shows how to call
it.

Private Function HasIncludeText(oDoc As Document) As Boolean
Dim oFld As Field
Dim bRet As Boolean
bRet = False
For Each oFld In oDoc.Fields
If oFld.Type = wdFieldIncludeText Then
bRet = True
Exit For
End If
Next
HasIncludeText = bRet
End Function

Sub demo()
If HasIncludeText(ActiveDocument) Then
MsgBox "There is at least one IncludeText field here"
Else
MsgBox "This document contains no IncludeText fields"
End If
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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