Reputation: 51
I have the following issue: I am trying to write a VBA macro in PowerPoint, whose sole purpose would be to run a macro that is contained in a COM PowerPoint addin (so a .dll file, not a .pptam). This COM PowerPoint is installed by default by my company, it's proprietary so I don't know have access to its source code.
This COM PowerPoint Addin appears under the name "AddinName" in my PowerPoint ribbon, and the .dll file is "myaddin.dll". The macro from this addin I'm trying to run is called "Macroname"
I have tried the following:
Application.Run "AddinName!MacroName"
But I get an error message.
Any idea on how to accomplish this?
Upvotes: -1
Views: 144
Reputation: 49455
It is not possible to call your COM add-in using the following command (like a VBA macro):
Application.Run "AddinName!MacroName"
In your VSTO/COM add-in you need to define and implement a COM interface which can be used from the VBA environment.
[ComVisible(true)]
public interface IAddInUtilities
{
void ImportData();
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInUtilities : IAddInUtilities
{
public void ImportData()
{
PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation as PowerPoint.Presentation;
if (presentation != null)
{
// do something
}
}
}
In the add-in file you also need to override function to expose the AddInUtilities
class to other Office Solutions:
private AddInUtilities utilities;
protected override object RequestComAddInAutomationService()
{
if (utilities == null)
utilities = new AddInUtilities();
return utilities;
}
And then you will be able to call your COM add-in in the following way:
Sub CallVSTOMethod()
Dim addIn As COMAddIn
Dim automationObject As Object
Set addIn = Application.COMAddIns("YourPowerPointAddin")
Set automationObject = addIn.Object
automationObject.ImportData
End Sub
Read more about that in the Walkthrough: Call code in a VSTO Add-in from VBA article.
Upvotes: 0