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.  
dmalovichAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
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.
dmalovichAuthor Commented:
Great. Do you have some sample code to show? Thanks....
Rory ArchibaldCommented:
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

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

dmalovichAuthor Commented:
This is the content of the cell where the link is changing values  =REDILink|'L1'!'ge;LP'  .  Where would I put this code?
Rory ArchibaldCommented:
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

dmalovichAuthor Commented:
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?
Rory ArchibaldCommented:
You'd need to replicate the statement for each I think

ActiveWorkbook.SetLinkOnData _
    "REDILink|'L1'!'ge;LP'", _
    "Macro1"
ActiveWorkbook.SetLinkOnData _
    "REDILink|'L1'!'ge;blah'", _
    "Macro1"
' and so on

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rory ArchibaldCommented:
Although you could just try specifying the common part of the formula:

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

and see if that works?
dmalovichAuthor Commented:
Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.