Any way to change VBA reference programmatically before VBA code is fired?

121 views
Skip to first unread message

Vladimir Macan

unread,
Mar 3, 2019, 4:12:10 PM3/3/19
to Excel-DNA
Hello guys,

I have a problem to solve using xll Addin built with Excel DNA. I need to change references in VBA code programmatically - remove broken (MISSING:) references and replace them with new ones pointing to different location.
Let's say I have this C# command wb.VBProject.References.Remove(refToRemove) to remove the ref.

When user opens a workbook, it is is available to me as Excel DNA Application.WorkbookOpen event argument. However it is fired after Excel's Sub Workbook_Open() and after any Function code is bound.
This leads to errors thrown by VBA just after workbook has been loaded, saying reference does not exist before I have a chance to replace it from within the addin's code.

If you have any thoughts or suggestions how can I solve this problem please share.

Thanks,
Vladimir

Ken Jackson

unread,
Mar 3, 2019, 7:03:04 PM3/3/19
to exce...@googlegroups.com
1. I would suggest opening up an instance of MS Excel.
2. Deselect your AddIn, click on OK.\
3. Run code in Debug mode and set a breakpoint just prior to process that causes the problem.
Hope that helps.


Virus-free. www.avast.com

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Vladimir Macan

unread,
Mar 4, 2019, 2:41:58 AM3/4/19
to Excel-DNA
Thanks for your answer. Debugging is not really needed, I know the issue - I have missing reference.
I have different problem to solve which is change it programmatically before code breaks.
Reply all
Reply to author
Forward
0 new messages