Solved

How do I archive files in an excel script?

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Formula to split product code 5 16
Merging spreadsheets 8 42
Saving excel document in lotus script 4 13
Need excel formula correction. 5 14
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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

803 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