Link to home
Start Free TrialLog in
Avatar of dmalovich
dmalovich

asked on

How can I use SetLinkOnData in excel to run a macro when a cell changes value from external link?

I have a list of stocks from cell A9 to A50.  I'm using dde links to get my data.  I would like to run a macro whenever one of the cells changes value.  SetLinkOnData seems the only way to do this.  The values are in column B.  
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

SetLinkOnData takes two string arguments. The first is the name of the DDE link, the second is the name of the procedure you want to run.
Avatar of dmalovich
dmalovich

ASKER

Great. Do you have some sample code to show? Thanks....
Only from the Help file - I don't use DDE functions:

ActiveWorkbook.SetLinkOnData _
    "WinWord|'C:\MSGFILE.DOC'!DDE_LINK1", _
    "my_Link_Update_Macro"

Open in new window

This is the content of the cell where the link is changing values  =REDILink|'L1'!'ge;LP'  .  Where would I put this code?
I would test it by running this (assuming you have a macro called macro1 that you want to run when the DDE updates) and then see if the macro is triggered.

Sub UpdateDDE()
ActiveWorkbook.SetLinkOnData _
    "REDILink|'L1'!'ge;LP'", _
    "Macro1"
End Sub

Open in new window

This worked.  Thanks.  This works for just this one link only though.  How can I do an entire row of stocks?  I'm watching more than 50 stocks.  How can I run the macro for all of them when data changes?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Although you could just try specifying the common part of the formula:

ActiveWorkbook.SetLinkOnData _
    "REDILink|'L1'", _
    "Macro1"

and see if that works?
Thanks.