Application.FileSearch - how to define .LookIn

S

Sue

I am updating a Word 2000 macro to 2003.
I used Application.FileSearch to recover inserted data and replace it with
place holders at the end of the macro. (So that the base document can be
re-used).
Now however I can not get the the text file called "MonthData.txt" to be
found.
It is there (and is created by the macro) and in the same directory as
everything else.
In Word 2000 I had .LookIn as "C:\My Documents".
What do I need in Word 2003?
Is there a short cut to get to the working directory?

Thank you for looking at this for me. Sue
 
J

Jay Freedman

If you always want to look in the same folder as the active document (which
is not necessarily "the same directory as everything else", depending on
what you mean by that), then you want

.LookIn = ActiveDocument.Path

That assumes the active document has been saved at least once, otherwise its
..Path will be an empty string. So you might want to say that if
Len(ActiveDocument.Path) = 0 then .LookIn =
Options.DefaultFilePath(wdDocumentsPath) which is usually C:\Documents and
Settings\<user name>\My Documents.

It gets worse: If you think your macro will eventually be moved to Word 2007
or later, you should be aware that Application.FileSearch has been removed
from VBA there (http://support.microsoft.com/kb/920229). There are
workarounds and replacements, but FileSearch itself will stop working.

BUT you can probably sidestep the whole mess by making your form the way it
should have been from the start, as a TEMPLATE from which you create a new
document (using File > New instead of File > Open) for each use. The new
document will automatically start with empty fields (placeholders), and
there will never be a risk of saving new data with the same name as the
"base document" and maybe losing old data. Also, the macro will stay only in
the template, not in the document, so Word's antivirus security mechanism
won't bother users with "disable or enable macros" prompts.

--
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