Opening an Excel Doc

Avslavedriver

Board Regular
Joined
Jun 22, 2004
Messages
55
Hello,

I'm using Access 97 and i'm trying to open an Excel Document inside a module using VBA code. Any suggestions

Thanks
 

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).
I have only been able to test this in XL2K

Code:
Private Sub cmdExcel_Click()
'WillR - opens a Spreadsheet & inserts 1 in A1 of Sheet1
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = New Excel.Application
With xlApp
    .Visible = True
Set xlWB = .Workbooks.Open("S:\Personal\XL\Test.xls", , False)
    With xlWB.Sheets("Sheet1")
        With .Range("A1")
        .Value = 1
        End With
    End With
End With
End Sub

Requires you to set a reference to the relevant Excel Object library in the Access VBE. Hope it helps
 
Upvote 0
The code looks great, but Excel.Application is giving me an Error in my Dim statement. I can't figure out why

Thanks
 
Upvote 0
Hullo! Did you remember to set a reference as Will suggested? When you are in the module edit screen, click Tools->References, and you should see a list of references. Make sure MS Excel (your version) is checked.

HTH (y)

P
 
Upvote 0

Forum statistics

Threads
1,221,821
Messages
6,162,157
Members
451,750
Latest member
pnkundalia

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