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!

Automatic macros in Excel

Status
Not open for further replies.

cbd

Programmer
Apr 4, 2002
18
US
I have an excel file with 3 sheets and about 40 graphs. The excel file connects to an external database when opened and populates the 3 spreadsheets with data. I have created a macro that automatically plots the graphs using the information in the 3 spreadsheets. My problem is that I want the macro to run automatically when the file is open but only after the spreadsheets have been updated from the database. I tried renaming my Auto_Open() but this runs the macro before the spreadsheets are updated. Is there any way to automatically run this macro after the file has connected to the external database.
 
hi cdb,

First, you ought to use the workbook/worksheet object events. So use the Workbook_Open event rather than Auto_Open. You can find the objects in the Project Browser and then within each object the event skeletons.

In this specific case, if you can change your links to Manual. Then, in the Workbook_Open event,
Code:
    For Each lnk In ActiveWorkbook.LinkSources(xlExcelLinks)
       Workbooks.Open Filename:=lnk, updatelinks:=3
    Next
Hope this helps :) Skip,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top