Stop "Save as" and Copy File

G

Guest

Could you help me to refine this program?

I have this statement (see below) that sends a message when the “file was
saved alreadyâ€. However, when I click “OK†the program “saves as†a copy of
the file instead of just STOP.
Basically, I do not want the program to save as a copy. I just want to stop
as soon as I click “OKâ€

Thanks in advance for your help.
Maperalia

‘************************************
If ThisWorkbook.Saved = False Then
MsgBox "File Has Been Saved Already"
Exit Sub
End If

ActiveWorkbook.SaveCopyAs Progname

‘************************************
 
G

Guest

Vasant;
Thanks for your quick response. I used the statement you advised me but I
got the following window message:

Run-time error ‘1004’
Cannot access read-only document ‘filename.xls’

Then after I click debug it is highlighting in the following statement:

ActiveWorkbook.SaveCopyAs Progname

Could you please tell me how to fix it?.. I would like to have the message
“The File Has Been Saved Already†after I hit the button’s macro for second
time. So I will know that I have to change the filename I order to save it.

See program below for reference

Regards.
Maperalia

‘*****Start of Program**************
Sub SaveExcelFile()
Dim boError As Boolean
Dim strError As String
Dim Tract As String
Dim WO As String
Dim Supplier As String
Dim Dates As String
Dim Time As String
Dim sFilename As String
Dim Progname As String
Dim Filename As String
'***************************************************************
'Setup File Name
strError = ""
boError = False
With Worksheets("Gradation Form")
If .Range("G2") = "" Then
boError = True
strError = strError & "WORK ORDER # "
End If
If .Range("G3") = "" Then
boError = True
strError = strError & "TRACT #"
End If
If .Range("C6") = "" Then
boError = True
strError = strError & "SUPPLIER "
End If
If .Range("G4") = "" Then
boError = True
strError = strError & "DATE "
End If
If .Range("G5") = "" Then
boError = True
strError = strError & "TIME"
End If
If boError = True Then
MsgBox "The Following Ranges have not been Typed Yet - " & strError
Exit Sub
Else
WO = Worksheets("Gradation Form").Range("G2")
Tract = Worksheets("Gradation Form").Range("G3")
Supplier = Worksheets("Gradation Form").Range("C6")
Dates = Worksheets("Gradation Form").Range("G4")
Time = Worksheets("Gradation Form").Range("G5")
Filename = "" & WO & "_" & Tract & "_" & Supplier & "_" & Dates &
"_" & Time & ""
Progname = "C:\Mario\Macro Samples\Excel\Gradation\Gradation Form
Rev1\" & Filename & ".xls"

If ActiveWorkbook.Saved Then
MsgBox "File Has Been Saved Already"
Exit Sub
End If


ActiveWorkbook.SaveCopyAs Progname



Call ListOfFileSave(Filename)


End If
End With
End Sub

‘*****End of Program**************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top