ThisFile = Range("E6").Value Chdir:="C:\Windows\Desktop\" ActiveWorkbook.SaveCopyAs Filename:=ThisFile End Sub
One way to do it is ;
ThisFile = Range("E6").Value
savedir = "C:\Windows\Desktop\"
ActiveWorkbook.SaveCopyAs FileName:=savedir & ThisFile & ".xls"
Ivan
ThisFile = Range("E6").Value Chdir:="C:\Windows\Desktop\" ActiveWorkbook.SaveCopyAs Filename:=ThisFile End Sub
Ivan,
Is it also possible to copy automatically to a floppy in A:\ after, say 45 minutes? What I'm asking for is additional VB code. I could use the code during examinations. I've always 3 to 4 students who forget to save or can't save their workbook to A:\.
Thanks.
Aladin
Aladin, this should help you;
Public RunWhen As Double
Public Const cRunIntervalHours = 0 ' Hours; Range 0 - 23
Public Const cRunIntervalMinutes = 45 ' Minutes; Range 0 - 59
Public Const cRunIntervalSeconds = 0 ' seconds; Range 0 - 59
Public Const cRunWhat = "SaveFile_Timed" ' Place the name of your routine here
'Use Now + TimeValue(time) to schedule something to be run when a specific amount of time
'(counting from now) has elapsed. Use TimeValue(time) to schedule something to be run at
'a specific time.eg TimeValue("21:30") runs it @ 9:30pm
Sub StartTimer()
RunWhen = Now + TimeSerial(cRunIntervalHours, cRunIntervalMinutes, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub
Sub SaveFile_Timed()
Dim ThisFile As String, Savedir As String, a
ThisFile = Range("E6").Value
Savedir = "A:\"
On Error GoTo ErrSaving
ActiveWorkbook.SaveCopyAs FileName:=Savedir & ThisFile & ".xls"
'To start over again call routine again
StopTimer
StartTimer
Exit Sub
ErrSaving:
MsgBox "Error#:= " & Err.Number & " = " & Err.Description, vbMsgBoxHelpButton, _
"Error", Err.HelpFile, Err.HelpContext
End Sub
Change as neccesary
eg. to automat this then place code to run Starttimer
in the workbook open event or Auto open
Ivan