S
Senapathy K
Hi,
I had posted a question regarding packaging of a Outlook macro. Taking Sue
Mosher's suggestion, I have now packaged it as a COM addin.
The setting for the load behaviour of my add in is "Startup".
I have taken the following code from MSDN article (
http://support.microsoft.com/kb/238228 ) to create 2 new buttons on the
"Standard" toolbar.
' this is in AddinInstance_OnConnection
Set oStandardBar =
Application.ActiveExplorer.CommandBars("Standard")
Set AFIButton = oStandardBar.Controls.Add(1)
With AFIButton
...
End With
Set IUSButton = oStandardBar.Controls.Add(1)
With IUSButton
...
End With
Now the problem is that when I load the Add in for the first time everything
is fine. 2 buttons are added. When I restart Outlook, the buttons are
getting added again. This is to be expected from the above code. But the
trouble is I am not able to find in any way whether the 2 buttons already
exist.
I have tried to check with the code from the same MSDN article
(http://support.microsoft.com/kb/238228) that says to check for the item
before adding:
' In case the button was not deleted, use the exiting one...
Set AFIButton = oStandardBar.Controls.Item("AFI Mail")
If AFIButton Is Nothing Then
Set AFIButton = oStandardBar.Controls.Add(1)
...
End if
I have tried this from both OnConnection and OnStartupComplete subroutines.
But this simply does not succeed. AFIButton is being returned as 'Nothing'
everytime. And new button is being added every time I restart Outlook.
I have even tried looping through the controls of the CommandBar using the
Index. However, the Count property of the CommandBars("Standard") is
returned as 0, so I cannot even loop through the CommandBar buttons and
check for the captions.
How can I check for existence of the button before adding afresh?
Regards,
Sena
I had posted a question regarding packaging of a Outlook macro. Taking Sue
Mosher's suggestion, I have now packaged it as a COM addin.
The setting for the load behaviour of my add in is "Startup".
I have taken the following code from MSDN article (
http://support.microsoft.com/kb/238228 ) to create 2 new buttons on the
"Standard" toolbar.
' this is in AddinInstance_OnConnection
Set oStandardBar =
Application.ActiveExplorer.CommandBars("Standard")
Set AFIButton = oStandardBar.Controls.Add(1)
With AFIButton
...
End With
Set IUSButton = oStandardBar.Controls.Add(1)
With IUSButton
...
End With
Now the problem is that when I load the Add in for the first time everything
is fine. 2 buttons are added. When I restart Outlook, the buttons are
getting added again. This is to be expected from the above code. But the
trouble is I am not able to find in any way whether the 2 buttons already
exist.
I have tried to check with the code from the same MSDN article
(http://support.microsoft.com/kb/238228) that says to check for the item
before adding:
' In case the button was not deleted, use the exiting one...
Set AFIButton = oStandardBar.Controls.Item("AFI Mail")
If AFIButton Is Nothing Then
Set AFIButton = oStandardBar.Controls.Add(1)
...
End if
I have tried this from both OnConnection and OnStartupComplete subroutines.
But this simply does not succeed. AFIButton is being returned as 'Nothing'
everytime. And new button is being added every time I restart Outlook.
I have even tried looping through the controls of the CommandBar using the
Index. However, the Count property of the CommandBars("Standard") is
returned as 0, so I cannot even loop through the CommandBar buttons and
check for the captions.
How can I check for existence of the button before adding afresh?
Regards,
Sena