?
Solved

backing up word files using VBA

Posted on 2002-06-04
5
Medium Priority
?
138 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:shantanuo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7055318
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
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 400 total points
ID: 7055321
sorry:
dim ff as string
ff=dir$("C:\My Documents\" & "*.doc",vbarchive)
do while ff<>""
   Selection.InsertFile FileName:="C:\My Documents\" & ff
   ff=dir$()
loop
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7055324
If you need to insert ALL files from C:\My Documents\" then
replace with:
ff=dir$("C:\My Documents\" & "*.*",vbarchive)

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851498
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
0
 

Expert Comment

by:SpideyMod
ID: 7912968
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question