Solved

Error in MyButton.Delete() in OnBeginShutdown event when using outlook comaddins

Posted on 2006-11-07
7
509 Views
Last Modified: 2008-02-01
Hi,
I developed small com-addins(VB6) to create 2 buttons on Startup & to remove the button on OnBeginShutdown.

Code Snippet:
Dim WithEvents cmdSaveinDM As Office.CommandBarButton
Set mnuOpenfrmDM = oHostApp.CommandBars.FindControl(Tag:="Open from DM")
cmdOpenfrmDM.Delete

above code removes Menu button when exit the application for Word,Excel,Powerpoint etc but except for Outlook.

even i tried with
Dim WithEvents cmdSaveinDM As Office.CommandBarButton
Set mnuOpenfrmDM = oHostApp.ActiveInspector.CommandBars.FindControl(Tag:="Open from DM")
cmdOpenfrmDM.Delete

still am getting error says object doesnt support.

Can anyone help me in this case????
0
Comment
Question by:encryptedheart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 17889321
Hi,

You don't specify which line the object doesn't support, but if you're just removing the buttons, why use WithEvents? Are you in a class module?

When I add my buttons from a COM add-in, I just set the Temporary argument to True while adding them.  And at the top of my RemoveButtons sub (called from OnDisconnect) I just put On Error Resume Next (since the buttons will be removed when it closes, and this way I won't get the random error like this when outlook disagrees with my code).

Lastly, are you sure you want ActiveInspector and not ActiveExplorer? Both have the commandbars object, though the Explorer is the more common place to put buttons, especially if you'll be calling them from OnBeginShutdown.  If you're adding them to an inspector object, just make them temporary as inspectors are closed frequently.

My opinion at least :)
Matt
0
 

Author Comment

by:encryptedheart
ID: 17889455
Hi,
Am getting error in the line
Set mnuOpenfrmDM = oHostApp.CommandBars.FindControl(Tag:="Open from DM")
I declared this button with events for different purpose.
Even i tried to set temporary:true as arguement while creating new button, it doesnt works.
I tried
Set mnuOpenfrmDM = oHostApp.ActiveExplorer.CommandBars.FindControl(Tag:="Open from DM")
 no use.
still getting same ..................
0
 
LVL 35

Expert Comment

by:mvidas
ID: 17889567
Hmm! Interesting..

I just added one to the Tools menu using:

 With oHostApp.ActiveExplorer.CommandBars("Tools").Controls.Add(msoControlButton, , , , True)
  .Tag = "Open from DM"
  .Caption = "Hello!"
 End With

Then used

 Dim mnuOpenfrmDM As CommandBarControl
 Set mnuOpenfrmDM = oHostApp.ActiveExplorer.CommandBars.FindControl(Tag:="Open from DM")
 If Not mnuOpenfrmDM Is Nothing Then
  mnuOpenfrmDM.Delete
 Else
  MsgBox "mnuOpenfrmDM is nothing"
 End If

And it did get deleted.. when I ran it a second time I got the message box.
Since you're the one adding the control, why use FindControl? Why not specify where it is and delete it that way? In my case (in the tools menu) :

 Set mnuOpenfrmDM = oHostApp.ActiveExplorer.CommandBars("Menu Bar").Controls("Tools").Controls("Hello!")

Though usually in my com add-ins, I add a separate menu after Help for any buttons, and then just delete the whole new menu.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:encryptedheart
ID: 17890113
Hi,
directly i tried to acces like
MsgBox oHostApp.ActiveExplorer.CommandBars.Item("File").Controls.Item("Open from DM").Tag
still getting same error
0
 
LVL 35

Expert Comment

by:mvidas
ID: 17890171
You would still have to reference the "Menu Bar" commandbar.  If you want to use the Item property like that, it would be:

 MsgBox oHostApp.ActiveExplorer.CommandBars.Item("Menu Bar").Controls.Item("File").Controls.Item("Open from DM").Tag

Though it could also be written shorter, as

 MsgBox oHostApp.ActiveExplorer.CommandBars("Menu Bar").Controls("File").Controls("Open from DM").Tag

Matt
0
 

Author Comment

by:encryptedheart
ID: 17890356
Hey i got the solution by using temporary flag to true.
actually my code written in a way if button already exist then not to insert the button,
so earlier i created button without temporary flag is set to true.
for the i should manually remove it.
now when i tried with that, its working fine.
thanks for your effort to help me.
0
 
LVL 35

Accepted Solution

by:
mvidas earned 100 total points
ID: 17890373
Glad to have helped! At the beginning of all my "InsertCommandButtons" subs, I always call "RemoveCommandButtons" in case they're still resident in there.  Thats the main reason I use On Error Resume Next in my remove sub, since often they won't be there when it is called
Matt
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question