By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 2,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

Open Excel from Access Command and auto_open macro

P: 5
Hi all!!

I need help, I have been stuck for a few days on this one. I am trying to open an excel table from a command button in Access. The excel table has an auto_open macro, that is supposed to run everytime I open excel.
When I navigate to the excel file, and open it, it autoruns the macro with no problems. When I go from Access hit the command, the excel table opens with no problem, but the macro does not auto run on start.
Here is the code I used to open my Excel table:

Dim appExcel As Object
Dim myWorkbook As Object
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("R:\RailTrace (Mauricio)\DBs\Rail Trace\MapExcelData.xls")
appExcel.Visible = True
Set appExcel = Nothing
Set myWorkbook = Nothing

Thank you in advance for your help.
Nov 24 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 1,287
Are you using Office 2007? I am and it worked with code very similar to yours.

Dim appExcel As Object
Set appExcel = CreateObject("Excel.Application")
appExcel.workbooks.Open "C:\ExcelVBA.xls"
appExcel.Visible = True

However, it didn't run the Workbook_Open() until I set my macro permissions and trusted the location of the file.
Nov 24 '08 #2

P: 5
ChipR,

Im working with excel 2003 and access 2000. Earlier I made it work running one command. I wrote a batch file to open my excel table, and I open the batch by running the command. It is working now, but I still want to figure out the other way.
Did you setup your securty for macros at low? (because I tried that and it didn't work) or did you put it at high and added a digital signature?? (which I didnt try because im not to sure how to do it)

Thanks for your response...
Nov 24 '08 #3

Expert 100+
P: 1,287
Actually, in 2007 I didn't have an option for low, so I had to just enable all macros for now.
:(
Nov 24 '08 #4

P: 1
Here would be how to do it in your code:

Dim appExcel As Object
Dim myWorkbook As Object
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("R:\RailTrace (Mauricio)\DBs\Rail Trace\MapExcelData.xls")

appExcel.Run "Auto_Open" '<---------Here it is !!!

appExcel.Visible = True
Set appExcel = Nothing
Set myWorkbook = Nothing
Feb 24 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.