M
maperalia
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**************
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**************