Solved

How do I archive files in an excel script?

Posted on 2008-06-09
3
150 Views
Last Modified: 2010-04-30
I have to write a macro that will be attached to a command button.  The mscro needs to move all files beginning with COSTB and STATUSB to a different folder.  They all have an .xls extension.  I need to move then from c:\my\documents to c:\my documents\backup.  I know this is simple for a person that writes macros all of the time....but I am just beginning.
0
Comment
Question by:ilrosebud26
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
StellanRosengren earned 125 total points
Comment Utility
Hi
You can use the FileSystemObject to move files (and do a lot of other things too). Here is an example that should do what you are asking for.

Regards,
Stellan
Sub ArchiveFiles()

    Dim fso As Object

    

    Dim sSourceDir As String

    Dim sTargetDir As String

    

    sSourceDir = "C:\my documents\"

    sTargetDir = "C:\my documents\backup\"

    

    Set fso = CreateObject("Scripting.FileSystemObject")

    

    fso.movefile Source:="COSTB*.xls", Destination:=sTargetDir

    fso.movefile Source:="STATUSB*.xls", Destination:=sTargetDir

    

End Sub

Open in new window

0
 

Author Comment

by:ilrosebud26
Comment Utility
This looks great, I am going to attach this to my command button in the morning.  I will let you know what happens!

Rosemary
0
 

Author Closing Comment

by:ilrosebud26
Comment Utility
Thanks for your help.  This worked great on my local drive.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now