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
Solved

How do I archive files in an excel script?

Posted on 2008-06-09
3
153 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

860 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