Solved

backing up word files using VBA

Posted on 2002-06-04
5
131 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
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 100 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

810 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