Access VBA to open xlsx file

CLCoop

Board Regular
Joined
May 30, 2018
Messages
56
Little help please I keep trying this code to open the STATECODE.xlsm file and I do have the Microsoft Excel 16.0 object library selected for tools. If it change the name of the file to any other file it seems to work to include other xlsm.
Option Compare Database

Function OpenExcelFromAccess()
Dim Myxl As Object

Set Myxl = CreateObject("Excel.Application")
With Myxl
.Application.Visible = True
.Workbooks.Open "H:\STATECODE.xlsm"

End With
End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Do you need to open the Excel file in VBA?
Whenever possible, I find it preferrable to link my Excel file to an Access Table object. No VBA required to do that, and any updates to the Excel file will be reflected in the Access table.
 
Upvote 0
smart... I made something hard didn't I... overthinking coding never! Thanks for the rethink.
 
Upvote 0
No worries!
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,247
Members
448,879
Latest member
oksanana

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