View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
norika norika is offline
external usenet poster
 
Posts: 6
Default creating a dos command in VBE

Hi all experts,

I am new to excel VBA, and need some help in this topic.

I got a excel data file , and its data would be changed day by day. In order
to trace mistakes and backup reason, I'm going to create some vba coding to
make a backup file in the same directory if I pressed a custom button in my
tool bar.

I create a stupid macro to save the active orginial file to another file
name, but after the code finish running, the existing file already replaced
by new file, because I used "SAVE AS" function in my coding.

What should I do if I just want an to copy my existing file to the same
directory?

Is it possible to run a dos command like " copy xxx.xls yyy.xls" in VBA?


Best Regards,


Newbie.

****************

Sub Macro1()
'
' marco save file
'

Dim wks As Worksheet
Dim spath As String
Dim sfilename As String
Dim sfilename1 As String
Dim sfilename2 As String
Dim fullname As String
Dim dayname As String
Dim monthname As String



Application.ScreenUpdating = False
Application.DisplayAlerts = False


spath = "c:\documents and settings\kay\my documents\logistics\semiwell\"

dayname = CStr(Day(Now()))
monthname = getmonth(Month(Now()))
sfilename1 = "Semi_Bup_" & dayname & monthname
sfilename2 = ".xls"
fullname = sfilename1 & sfilename2

ActiveWorkbook.SaveAs Filename:=(spath & fullname), _
FileFormat:=xlNormal, Password:="", _
writerespassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False

addtomru = True


End Sub