we have a c# com object which is called from vba codes in various spreadsheets, is there a way to log the source that invoke the com object? i.e. excel file name, workbook etc?
Asked
Active
Viewed 61 times
2 Answers
0
You could try using introspection to learn about the calling method. I'm not sure that this will work in this case because it's being called through the COM system and that might hide the origin. Here's how you could try it anyway:
How do I get the calling method name and type using reflection?
0
If you have control over both the VBA code and the C# code, you could simply add an extra parameter that will be logged as the 'name' of the calling COM object. You can then customize that parameter in each item that calls it.
For instance. c#
[comvisible(true)]
public void doStuff(string callingName, object otherarg, object anotherarg)
{
Console.writeline("Called by " + callingName);
//blah blah blah
}
vba 1
set tmp = ReferenceToCSharpComObject
call tmp.doStuff("Example VBA Script", null, null)
vba 2
set tmp = ReferenceToCSharpComObject
call tmp.doStuff("Second VBA Example", null, null)

ashbygeek
- 759
- 3
- 20