Fix error message '1004'

G

Guest

Could you please help to fix this program? (see program below). When I hit
the macro' button for second time 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 macro's button for second
time. So, I will not have this error message again. Besides, I will know
that I have to change the filename I order to save it.

Thanks in advance.
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**************
 
M

Mike Fogleman

Check to see if it is saved, if it is do nothing:
Sub IsSaved ()
If ThisWorkbook.Saved = True Then
Exit Sub
Else
MsgBox ("not Saved")
End If
End Sub

Mike F
 
G

Guest

Mike;
Thanks for your advise. I ran the program but unfortunately does not work in
way I need.
I got the message "Not Save" when I click the macro for first time.
Basically, I would like to have the message "The File Has Been Saved
Already" after I hit the macro's button for second time. So I know that has
been saved.

Regards.
Maperalia
 

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