Code works in Outlook, but not in VB 6

H

Howard Kaikow

The code below runs correctly in Outlook 2003.

When I try to use the code in VB 6, or in Word 2003, I get an Error 91 on
the Set
cbrOutlookActiveMenuBar line.
The VB 6 project includes references to the Outlook and Office libraries.

What did I screw up?
----------------------------------------------------
Public Sub RunListOutlookControls()
Dim cbrOutlookActiveMenuBar As Office.CommandBar
Dim cbrOutlookTools As Office.CommandBarControl
Dim cbrOutlookToolsSend As Office.CommandBarControl
Dim appOutlook As Outlook.Application
Dim oCtl As Office.CommandBarControl

Set appOutlook = New Outlook.Application

Set cbrOutlookActiveMenuBar =
appOutlook.ActiveExplorer.CommandBars.ActiveMenuBar
Set cbrOutlookTools =
appOutlook.ActiveExplorer.CommandBars.ActiveMenuBar.Controls("Tools")
Set cbrOutlookToolsSend = cbrOutlookTools.Controls("Send/Receive")
MsgBox cbrOutlookToolsSend.Caption

appOutlook.Quit
Set appOutlook = Nothing
Set cbrOutlookActiveMenuBar = Nothing
Set cbrOutlookTools = Nothing
Set cbrOutlookToolsSend = Nothing
End Sub
 
S

Sue Mosher [MVP-Outlook]

Do you have an ActiveExplorer window at that point in your code's execution?
If ActiveExplorer returns Nothing, you have no Explorer windows open, so no
command bars are available.
 
H

Howard Kaikow

Perhaps I have to make Outlook visible?

But I do not see any "Visible" property for Outlook.
 
S

Sue Mosher [MVP-Outlook]

To make Outlook visible, you should show an Explorer window.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top