Muller Stephan
Posts: 50
Joined: 2010-03-11
|
Hi guys,
I am trying to execute an Outlook Macro from my Addin. I read on the forum that the "OnAction" of Office Buttons should be used for that. Since I need dynamic macro execution, I simply dynamically add a toolbar which should execute my macro. Unfortunately, that does not work. How can I execute a macro from my addin? I am attaching the code:
Microsoft.Office.Core.CommandBar commandBar;
Microsoft.Office.Core.CommandBarButton firstButton;
Microsoft.Office.Core.CommandBarButton secondButton;
private void adxCommandBarButton1_Click(object sender)
{
try
{
commandBar = OutlookApp.ActiveExplorer().CommandBars["Test"];
}
catch (ArgumentException e)
{
// Toolbar named Test does not exist so we should create it.
}
if (commandBar == null)
{
// Add a commandbar named Test.
commandBar = OutlookApp.ActiveExplorer().CommandBars.Add("Test", 1, Type.Missing, true);
}
try
{
// Add a button to the command bar and an event handler.
firstButton = (Microsoft.Office.Core.CommandBarButton)commandBar.Controls.Add(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
firstButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
firstButton.Caption = "button 1";
firstButton.Tag = "button1";
firstButton.OnAction = "testMakro";
//firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
firstButton.Execute();
// Add a second button to the command bar and an event handler.
secondButton = (Microsoft.Office.Core.CommandBarButton)commandBar.Controls.Add(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
commandBar.Visible = true;
}
catch (ArgumentException e)
{
MessageBox.Show(e.Message);
}
} |
|
Eugene Astafiev
Guest
|
|
Muller Stephan
Posts: 50
Joined: 2010-03-11
|
Hey Eugene,
thank you for your quick answer. The security settings were not the problem.
However the problem was that my Macro was not accessible because it was "ThisOutlookSession.TestMacro" not "TestMacro". When I created a new sub and called it just "TestMacro", the code worked.
So the solution is working, thank you!
Kind Regards
Stephan |
|
Eugene Astafiev
Guest
|
You are welcome, Stephan! ;-) |
|