Code works in Outlook, but not in VB 6

  • Thread starter Thread starter Howard Kaikow
  • Start date Start date
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
 
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.
 
Perhaps I have to make Outlook visible?

But I do not see any "Visible" property for 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
 
Back
Top