Results 1 to 5 of 5

Run time error (Err=9) when saving file using saveas

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Run time error (Err=9) when saving file using saveas

    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
    Last edited by welchs101; 03-24-2012 at 10:51 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1