Saving Method Failed

radon

Registered User.
Local time
Today, 12:53
Joined
Jul 30, 2008
Messages
33
I was tasked with debugging code and stummbled across this error message
"Method 'Save' of object '_Workbook' failed"
Here's the portion of the code that pertains to this...

Set TestBook = Workbooks.Open(XlsPath & strXlsFileName)
Set TestSheet = TestBook.Worksheets(1)

' Delete First Row in the XLS
Cells(1, 1).EntireRow.Delete

' Last 2 columns in XLS
For k = 1 To 2
Cells(1, 3).EntireColumn.Delete
Next k

finalrow = TestSheet.Range("A65000").End(xlUp).Row

For i = 1 To finalrow
TestSheet.Cells(i, 3) = UFirstthree
Next i
TestBook.Application.DisplayAlerts = False
TestBook.Save
TestBook.Application.Quit
strXlsFileName = Dir()

Loop
MsgBox "Data processing successful."
 
No, though I may have found the solution and it lays outside of the code I posted. A couple "DoCmd.SetWarnings" where in the code with the incorrect version of true/false after them. That may have been the problem but if anybody else sees an issue please let me know.
 
Now I'm getting the same error message about the saving method failing.
 
I thought I would post the entire set of code...

Private Sub cmd_process_xls_Click()
On Error GoTo Err_cmd_process_xls_Click
' Switch off all the WARNING msgs.
DoCmd.SetWarnings False
Dim strXlsFileName As String
Dim XlsPath As String
Dim WBname As String
Dim Trimname As String
Dim Firstthree As String
Dim UFirstthree As String
Dim TestBook As Workbook
Dim TestSheet As Worksheet
Dim finalrow As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
MsgBox "Please verify that all the file names begin with the names of the respective sites."
MsgBox "You are going to process the XLS files. This command will delete the non-data columns and rows and will add Site Names to respective files."
XlsPath = xls_file_path.Value
strXlsFileName = Dir(XlsPath & "*.xls")
Do While strXlsFileName <> ""

WBname = strXlsFileName
Trimname = LTrim(WBname)
Firstthree = Left(Trimname, 3)
UFirstthree = UCase(Firstthree)
If (StrComp(UFirstthree, "whi", vbTextCompare) = 0) Then
UFirstthree = "WHT"
End If
If (StrComp(UFirstthree, "bow", vbTextCompare) = 0) Then
UFirstthree = "BOW"
End If
If (StrComp(UFirstthree, "con", vbTextCompare) = 0) Then
UFirstthree = "CON"
End If
If (StrComp(UFirstthree, "hun", vbTextCompare) = 0) Then
UFirstthree = "HUN"
End If
If (StrComp(UFirstthree, "wol", vbTextCompare) = 0) Then
UFirstthree = "WOL"
End If
If (StrComp(UFirstthree, "dav", vbTextCompare) = 0) Then
UFirstthree = "DAV"
End If

Set TestBook = Workbooks.Open(XlsPath & strXlsFileName)
Set TestSheet = TestBook.Worksheets(1)

' Delete First Row in the XLS
Cells(1, 1).EntireRow.Delete

' Last 2 columns in XLS
For k = 1 To 2
Cells(1, 3).EntireColumn.Delete
Next k

finalrow = TestSheet.Range("A65000").End(xlUp).Row

For i = 1 To finalrow
TestSheet.Cells(i, 3) = UFirstthree
Next i
TestBook.Application.DisplayAlerts = False
TestBook.Save
TestBook.Application.Quit
strXlsFileName = Dir()

Loop
MsgBox "Data processing successful."
' Switch on the WARNING msgs.
DoCmd.SetWarnings True
Exit_cmd_process_xls_Click:
Exit Sub
Err_cmd_process_xls_Click:
MsgBox Err.Description
Resume Exit_cmd_process_xls_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom