Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Open all docs in folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 31 Mar 2006 11:48 GMT
i am using €office 97 upwards.

Cansomeone asist me with some code which looks in a particular folder, opens
each document one by one and does something then saves it and closes it and
open next document.

Open each doc in folder 1 by 1

with active doc

do something

save document

close document

next document

Signature

Mark

Jezebel - 31 Mar 2006 12:31 GMT
Dim pFileName as string
Dim pDoc as Word.Document

pFileName = Dir("C:\MyFolder\*.doc")
Do until len(pFileName) = 0
   set pDoc = Documents.Open(pFileName)
   ... do whatever with pDoc
   pDoc.Close SaveChanges:=TRUE
   pFileName = Dir
Loop

>i am using ?office 97 upwards.
>
[quoted text clipped - 15 lines]
>
> next document
Mark - 31 Mar 2006 14:34 GMT
Thanks,

i have tried this and altered the folder path to suit, it finds the first
file and then debugs on the 'set pDoc = Documents.Open(pFileName)' line with
a run-time rror 5174 'this file could not be found'.

Try one of the following
Check spelling of the document
Try a different filename

Equally when I change the path to 'R' drive (a network drive) it doesn't
find anything and end subs.

Any ideas?
Signature

Mark

> Dim pFileName as string
> Dim pDoc as Word.Document
[quoted text clipped - 26 lines]
> >
> > next document
Doug Robbins - Word MVP - 31 Mar 2006 15:41 GMT
You need to use:

Dim pFileName As String
Dim pDoc As Word.Document

pFileName = Dir("C:\MyFolder\*.doc")
Do Until Len(pFileName) = 0
   MsgBox pFileName
   Set pDoc = Documents.Open("C:\MyFolder\" & pFileName)
   pFileName = Dir
Loop

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks,
>
[quoted text clipped - 42 lines]
>> >
>> > next document

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.