Link to home
Start Free TrialLog in
Avatar of shantanuo
shantanuo

asked on

backing up word files using VBA

Hi

Here is the simple macro I have recorded in Word.
It creats a backup.doc file after inserting the contents of all
the .doc files saved in My Documents.

I can run it if I know the exact file name. But if I don't know the
names of all the files, how can get the first word file, insert the
contents, then grab the second one for backup.


Sub Macro3()
'
' Macro3 Macro
' Macro recorded 04/06/02 by shantanu

Documents.Add DocumentType:=wdNewBlankDocument
ChangeFileOpenDirectory "C:\My Documents\"
Selection.InsertFile FileName:="AGREEMENT OF LEAVE AND
LICENCE.doc"

Selection.InsertFile FileName:="elite.txt"

ActiveDocument.SaveAs FileName:="backup.doc"

End Sub

Thanks
Shantanu Oak
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

with a loop you could easily grab all documents names:
dim doc as document
for each doc in application.documents
   debug.print doc.name
next
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you need to insert ALL files from C:\My Documents\" then
replace with:
ff=dir$("C:\My Documents\" & "*.*",vbarchive)

Hi shantanuo,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

shantanuo, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
Avatar of SpideyMod
SpideyMod

per recommendation

SpideyMod
Community Support Moderator @Experts Exchange