Solved

How do I archive files in an excel script?

Posted on 2008-06-09
3
151 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
ID: 21747587
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
ID: 21755054
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
ID: 31465561
Thanks for your help.  This worked great on my local drive.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

863 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

17 Experts available now in Live!

Get 1:1 Help Now