ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   creating a dos command in VBE (https://www.excelbanter.com/excel-programming/294392-creating-dos-command-vbe.html)

norika

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








Vasant Nanavati

creating a dos command in VBE
 
Look at the SaveCopyAs method.

--

Vasant

"norika" wrote in message
...
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











All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com