+ Reply to Thread
Results 1 to 7 of 7

error 1004 - unable to save file

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2013
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    94

    error 1004 - unable to save file

    dear, can someone help out please?

    I am unable to save the file. I get following error 1004 document not saved

    ActiveWorkbook.SaveAs Filename:=xlsname, FileFormat:=xlOpenXMLWorkbookMacroEnabled, ConflictResolution:=xlLocalSessionChanges
    Option Explicit
    Sub Upgrade()
    Application.DisplayAlerts = False
    Dim tempSheet As Worksheet
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim FileToOpen As String
    Dim Sheet1 As Worksheet
    Dim wb2 As Workbook
    Dim total As Integer
    Dim xlsname As String
    
    Application.DisplayAlerts = False
    
    
    Set wb = ActiveWorkbook ' Or ThisWorkbook, or Workbooks("filename.xlsx"), etc.
    Set tempSheet = wb.Sheets.Add
    Application.DisplayAlerts = False
    For Each ws In wb.Worksheets
        Application.DisplayAlerts = False
        If ws.Name <> tempSheet.Name Then
            ws.Delete
        End If
        Application.DisplayAlerts = False
    Next
    
    'Now open the other workbook for which the sheets need to be copied:
    FileToOpen = Application.GetOpenFilename
    
    If FileToOpen = Empty Then
        MsgBox "No File Specified.", vbExclamation, "ERROR"
        Exit Sub
    Else
        Set wb2 = Workbooks.Open(Filename:=FileToOpen)
    
       For Each Sheet1 In wb2.Sheets
       
            With Sheet1.UsedRange
                Sheet1.Copy after:=wb.Sheets(wb.Sheets.Count)
                End With
        Next Sheet1
    
    End If
    'remove tempsheet
    tempSheet.Delete
    
    'close copied content file (filetoopen)
    wb2.Close
    
    ' save generated file as new file
    xlsname = Application.GetSaveAsFilename & "xlsm"
    
    Application.DisplayAlerts = False
    
    ActiveWorkbook.SaveAs Filename:=xlsname, FileFormat:=xlOpenXMLWorkbookMacroEnabled, ConflictResolution:=xlLocalSessionChanges
    
    Set wb = ActiveWorkbook
    ActiveWorkbook.Close False
    
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: error 1004 - unable to save file

    In no way did I test the code, but I see
    & "xlsm"
    Would it not be
     & ".xlsm"

  3. #3
    Registered User
    Join Date
    06-03-2013
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: error 1004 - unable to save file

    still not working, getting same error 1004 document not saved...

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,285

    Re: error 1004 - unable to save file

    Try this way.

    xlsname = Application.GetSaveAsFilename
    xlsname = xlsname & "xlsm"
    Also you switch off DisplayAlerts 4 times. Where do you switch it back on again???
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    06-03-2013
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: error 1004 - unable to save file

    when I set the display alert to true - i get following error message : there isn't enough memory to complete this action. Try using less data or closing other applications. T o increase memory availability consider: using a 64 bit version of microsoft excel or adding memory to your device

    so that's the reason why the document cannot be saved , but how to solve this one?

  6. #6
    Registered User
    Join Date
    06-03-2013
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: error 1004 - unable to save file

    Could it be I need to copy only rows with data rather and full sheets? I entered though Sheet1.Usedrange... How would I need to adapt the code to use less memory?
    Last edited by rickmeister; 06-07-2017 at 09:55 AM.

  7. #7
    Registered User
    Join Date
    06-03-2013
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: error 1004 - unable to save file

    solved - if I clear content of the sheet and copy the content I do not get the error msg.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Error 1004 when trying to save file with name generated from cell value
    By Terios1951 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2015, 04:49 PM
  2. Runtime error 1004 when trying to save file via VBA
    By avh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2015, 03:20 AM
  3. How to delete unwanted backup files after third backup?
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2014, 10:11 AM
  4. [SOLVED] run time erro 1004 - unable to save file
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2014, 12:06 AM
  5. [SOLVED] Run-time error 1004/Save file macro
    By egglee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-04-2013, 06:22 AM
  6. SaveCopyAs Runtime Error 1004 - save a backup without altering open file
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-27-2013, 08:11 PM
  7. 1004 Error due to nasty server - unable to error handle
    By PuppyOnTheRadio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 06:39 AM

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