Solved

backing up word files using VBA

Posted on 2002-06-04
5
129 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
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now