excel - Macro doesn't run when data is refreshed? -
i have written following code detect change in value of cell , run macro, when data refreshed due data connection code doesn't work.
private sub worksheet_change(byval target range) if target.address = "$a$2" if target.value = 1 taskid = shell("c:\imawesome.bat", vbnormalfocus) end if if target.value = 0 taskid = shell("c:\sender.bat", vbnormalfocus) end if end if end sub the code works when manually enter data in cell. please suggest code runs when data refreshed.
following microsoft article kb213187 , assuming data connection querytable
you can try this
create new module , put code in it
public withevents qt querytable private sub qt_beforerefresh(cancel boolean) 'do stuff here end sub then on module create class
dim x new class1 sub initialize_it() set x.qt = thisworkbook.sheets(1).querytables(1) end sub and make sure initialize_it runs every time open document.
be aware code works 1 qquerytable per document, modifications needed if have more.
hope helps.
Comments
Post a Comment