Results 1 to 4 of 4
  1. #1
    lowells is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    8

    Excel workbook changes won't save from Access macro

    Hey,
    I've written the code below to export then format a report from Access 2013 to an Excel workbook. It works great until it gets to the xlWb.Save line where I get the following error.
    Run-time error '1004':
    Method 'Save' of object '_Workbook' failed

    I suspect the problem might have something to do with me running Office 2013 but trying to save as a .xls file which is an older compatibility mode version. But I'm just guessing.


    Any thoughts on how I can get these changes to save?

    Code:
    Option Compare Database
    
    Sub ExportOpenItemsToExcel()
    ' first export the raw report data to an Excel workbook in the currentdb's folder
        sPath = CurrentProject.Path
        DoCmd.OutputTo acOutputReport, "rptOpenActionItems", acFormatXLS, sPath & "\OpenActionItemsReport.xls", False
        
        
        'now format the Excel Workbook from this Access macro
        Dim xlAPP As Object
        Dim xlWS As Object
        Dim xlWb As Excel.Workbook
        
        Set xlAPP = CreateObject("excel.application")
        Set xlWb = xlAPP.Workbooks.Open(sPath & "\OpenActionItemsReport.xls")
        Set xlWS = xlWb.Worksheets("Open Action Items")
        xlAPP.Visible = True
    
        xlWS.Range("A1:H2").Font.Bold = True
        xlWS.Range("A1:H2").HorizontalAlignment = xlCenter
        xlWS.Cells(1, 2).NumberFormat = "[$-F400]h:mm:ss AM/PM"
        xlWS.Columns("C:C").ColumnWidth = 14.14
        
        xlWb.Save
        
        Set xlWS = Nothing
        Set xlWb = Nothing
        Set xlAPP = Nothing
    
    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Try "xlWB.SaveAs sPath & "\OpenActionItemsReport.xls",FileFormat:=1

    No guarantees!

  3. #3
    lowells is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    8
    Thanks! That worked!

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    How nice!

    Please mark it solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-10-2016, 10:12 AM
  2. Save and close Excel Workbook
    By scoe in forum Access
    Replies: 5
    Last Post: 07-30-2013, 08:50 AM
  3. Replies: 4
    Last Post: 12-17-2012, 01:21 PM
  4. Replies: 1
    Last Post: 04-30-2012, 05:10 PM
  5. Replies: 1
    Last Post: 04-05-2012, 01:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums