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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Word docs in Dir 2

Status
Not open for further replies.

Cloonalt

Programmer
Jan 4, 2003
354
US
I have to loop through Word documents in a directory -
the documents all have a name that is five digits, with a three digit extension. The extension can be 001, 002, 003, etc. (Not the .doc extension, but a three digit addition to the name of the document)

For example, right now I am using:

oapp.Selection.InsertFile "C:\" & Batch & "001.doc" - batch being a variable that I get from a recordset.

I need to grab the document with the highest number extension for each batch number. Think I can do this? Any ideas?

Any help is appreciated.

Thanks.
 
A starting point (typed, untested):
doc = LCase(Batch & "001.doc")
f = LCase(Dir("C:\" & Batch & "???.doc"))
While f <> ""
If f > doc Then doc = f
f = LCase(Dir)
WEnd
oapp.Selection.InsertFile "C:\" & doc

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
cloonalt,

Another approach in your starting thread705-1229476
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top