Solved

How do I archive files in an excel script?

Posted on 2008-06-09
3
155 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
[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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
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 longer labels with horizontal bar charts instead of the vertical column chart.

717 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