Solved

backing up word files using VBA

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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