Share via

Excel: macro running after external data query when opening file

Anonymous
2011-08-24T18:21:48+00:00

My Excel file needs to have the two things happen automatically whenever someone opens it:

  1. Import external data using a query
  2. Run a macro to manipulate/move data within the workbook

** In that order.

I know how to create the query so it automatically runs upon startup, and I know how to put run a macro using Workbook_Open().  But doing these causes the macro to run first, and the data query second.  I need to reverse that order as indicated above.

Can anyone tell me how to do that?

Note I'm a total beginner in VB but pretty advanced in most of Excel.

Thanks so much y'all.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Andreas Killer 144.1K Reputation points Volunteer Moderator
2011-08-28T13:46:46+00:00

Call the Refresh method of your query in Workbook_Open before you call your macro, i.E.:

Sheets("Sheet1").QueryTables(1).Refresh

Andreas.

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2011-08-28T20:56:01+00:00

Hi

Andreas is correct.

It would be best not to update automatically on startup, infact disable it from doing so.  The control the refresh/update in your Workbook_Open macro.

This thread may contain some useful code for how to do the update and have the the macro run after the data refresh has completed.

http://social.technet.microsoft.com/Forums/en-US/excel/thread/ebf70407-6411-485b-a464-5aee1236c61e

Hope this helps

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful