+ Reply to Thread
Results 1 to 2 of 2

Open method of object failed error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Open method of object failed error

    I obtained some Access code from a co-worker that is used to open query data in a pre-created, pre-formatted, Excel spreadsheet that resides on my local hdd.

    Here is the code:

    Public Function OpenXls(ByVal strQueryName As String, strFilename As String)
    On Error GoTo OpenXls_err
    
    Dim strFullFileName As String
    Dim strTempDir As String
    Dim appexcel As Object
    
    'Set temp dir
    strTempDir = Environ("WINDIR") & "\Temp\"
    strFullFileName = strTempDir & strFilename
    
    
    'Create spreadsheet
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strQueryName, strFullFileName, True
    
    
       Set appexcel = CreateObject("Excel.Application")
       'Open Workbook
       appexcel.workbooks.Open strFullFileName
       appexcel.Visible = True
        
    Exit Function
    
    OpenXls_err:
    MsgBox "Error (" & CStr(Err.Number) & ") " & Err.Description, _
            vbExclamation, "Error!"
    The code works great except for in one circumstance. When I add a query to the Excel sheet (from Access or MS Query) and attempt to run this code I get a ~ "workbook open method of object failed error".

    I want to be able to open the Excel sheet via this code, refresh the query already contained in the Excel sheet, and be done.

    Obviously adding the query to the sheet is causing my error. Is there a different "Open method" that could be used?

  2. #2
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Open method of object failed error

    Still haven't figured this out. Alternatives are always welcome!

+ Reply to Thread

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