Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run Excel Macro automatically

Status
Not open for further replies.

sunnywink

Technical User
Oct 6, 2002
49
FR
Hi all,

I would like an Excel macro run automatically
after user has finished query to get external data from Access database.

Is there a way where I can set an event procedure to provoke the macro automatically after user finished querying? Can Excel 97 capture and recognise the event?

Thanks in advance!

 
Record the "refresh data" or record the "edit query / return data to excel event as a macro then splice that code into your on workbook open event along with your other code.

 
Thanks but there is another problem. In the program, upon opening the Excel file, the user will be first prompted to key in a key word to query from access database.

I added the the Refresh data command into the Auto_open() macro before other command lines, so that the user is able to do query first before the other lines are executed.

However, upon opening the file, instead of being prompted to key in key word to do query from Access, an error message appears as follow:
" Run-time error'1004':
Application-defined or object-defined error"

The Refresh data command that I added is as follow:
Selection.QueryTable.Refresh BackgroundQuery:=False
 
Then record the Edit process start the macro recorder then(right click > edit query) then when msquery opens simply select file > return data to excel...then stop macro

that way, when you view the code, you will see the sql statement where you can splice / concatenate a variable obtained from an inputbox.

Make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top