Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issues w/IF/FIND statements in Word VBA

Status
Not open for further replies.
Oct 13, 2004
39
US
Hi all!

I have placed the attached code into the code window of MS Word's Normal.dot in the Document_open event so that it will run automatically (I highlight all the docs that I want affected by this script and press enter to fire them all off - this method works fine - just some background)

The code works, no errors, with the exception of the first part fo the if statement. I tested this on 3 documents.

one that contained the text: LOCATION(S): THERE
one that contained the text: LOCATION(S): HERE
one that contained the text: LOCATION(S): THERE; HERE

The idea is that if it has the word: HERE in it, then write the filename and title to a log file..

after running all three of these test docs through the script, only the one that said: LOCATION(S): THERE; HERE was in the log

my question is, what am i doing wrong that the one that contained the text: LOCATION(S): HERE does not show up in my log?

I WOULD GREATLY APPRECIATE ANY HELP IN THIS!!! :)

====================

Sub notThere()

Selection.HomeKey Unit:=wdStory ' just to be safe, start at the top of doc
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ' view header
Selection.Find.ClearFormatting
With Selection.Find
.Text = "LOCATION(S):" & vbTab & "HERE"
If .Execute = True Then
Call getTitle 'get title and filename and write to log file
Exit Sub
Else
Selection.HomeKey Unit:=wdStory ' just to be safe, start at the top of doc
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ' view header
Selection.Find.ClearFormatting
With Selection.Find
.Text = "LOCATION(S):" & vbTab & "THERE; HERE"
If .Execute = True Then
Call getTitle 'get title and filename and write to log file
Else
ActiveDocument.Close 'if it is neither of these options, kill document
End If
End With
End If
End With
End Sub
 
pls clarify

1. r u only looking in headers?
2. is possible string in doc does NOT have tab in it?
 
yes only looking in headers and there IS a tab in between every instance - it is a set documentation standard

thanks!
 
Hi cliffhanger9,

It seems to work for me and there's no obvious reason it shouldn't. No chance, perhaps, you have a space one side or other of the tab is there?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top