I have the following file designed to save a file. I have NO idea why this occurring but i get a run time err #9.
Any ideas?
Sub save_combined_file(fl_combined As String, ws_combined As String, _
pth_save As String, save_error As Boolean)
'Dim New_file_name1 As String
Dim fl_new_combined As String
'create file name with EXTENSION
fl_new_combined = "Combined_Comment_File" + ".xlsx"
'**Start:***save file
'turn display prompts off
Application.DisplayAlerts = False
'note: pth_save should have "\" as the last character instring
New_file_name1 = pth_save & fl_new_combined
'if file to be saved is already open then close it
'If AlreadyOpen(fl_new_combined) Then Workbooks(fl_new_combined).Close
On Error Resume Next
save_error = False
Workbooks(fl_combined).Worksheets(1).Activate
'save file: FileFormat = 51 = xlOpenXMLWorkbook which means the extension will be ".xlsx"
'Workbooks(fl_combined).SaveAs FileName:=New_file_name1, FileFormat:=51, CreateBackup:=False
ActiveWorkbook.SaveAs FileName:=New_file_name1, FileFormat:=51, CreateBackup:=False
'if there is an error saving the file then alert user and stop the program
If Err <> 0 Then
MsgBox (Err.Number)
save_error = True
If Err.Number = 1004 And Len(New_file_name1) > max_file_name_path Then
MsgBox ("Error saving file. The file name + directory-path is larger than " & max_file_name_path & ". Program will now end.")
Else
MsgBox ("There was an error saving the file. The program will now stop.")
End If
Application.DisplayAlerts = False
Err.Clear
On Error GoTo 0
'turn back on display prompts
Application.DisplayAlerts = True
Exit Sub
End If
On Error GoTo 0
'turn back on display prompts
Application.DisplayAlerts = True
'the consolidated file has a new file name
fl_combined = fl_new_combined
MsgBox ("jlkjl")
'close the combined file.
If AlreadyOpen(fl_combined) Then Workbooks(fl_combined).Close
End Sub
Bookmarks