Open excel document

skinny220

New Member
Joined
Jan 10, 2015
Messages
34
Does anyone know an access VBA, I could use to open an excel file on my desktop called Show Inventory.xls?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Re: Microsoft Excel

Seems like your second post has been spammed - shame as the thread won't appear on Zero Reply Posts anymore.

This is how I open an Excel file from Access:
You'll need to create an instance of Excel that Access can reference:
Rich (BB code):
Public Function CreateXL(Optional bVisible As Boolean = True) As Object


    Dim oTmpXL As Object


    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Defer error trapping in case Excel is not running. '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    On Error Resume Next
    Set oTmpXL = GetObject(, "Excel.Application")
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'If an error occurs then create an instance of Excel. '
    'Reinstate error handling.                            '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If Err.Number <> 0 Then
        Err.Clear
        On Error GoTo ERROR_HANDLER
        Set oTmpXL = CreateObject("Excel.Application")
    End If
    
    oTmpXL.Visible = bVisible
    Set CreateXL = oTmpXL


    On Error GoTo 0
    Exit Function


ERROR_HANDLER:
    Select Case Err.Number
        
        Case Else
            MsgBox "Error " & Err.Number & vbCr & _
                " (" & Err.Description & ") in procedure CreateXL."
            Err.Clear
    End Select
    
End Function

Then in another procedure you'll need a couple of variables to hold the reference to Excel and another to the workbook file.

Rich (BB code):
    Dim oXLApp As Object            'Reference to Excel Application.
    Dim oXLWrkBk As Object          'Reference to workbook.

    Set oXLApp = CreateXL() 'Creates the instance of Excel.
    Set oXLWrkBk = oXLApp.WorkBooks.Open(full filename & path, False)



NB: Full filename and path will be something like "C:\Documents and Settings\ADMINNOT\Desktop\Book2.xls"
 
Upvote 0

Forum statistics

Threads
1,221,902
Messages
6,162,724
Members
451,782
Latest member
LizN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top