Crash when using GetInspector


T

technomane

Hello all,
hope you can help me with my problem here. The following code crashe
at line "Set myInspector = myItemb.GetInspector" (Outlook completel
crashes and needs to restart). I have no idea why this happens. Fro
what I've tried, it only crashes when the macro is started right afte
OL startup, while no inspector item was yet launched. When I click o
e.g. "New E-Mail" first (open/close the inspector), it will not crash.

Purpose of the whole thing is to add a user-defined command bar t
every new inspector item (like you would do via "customize" -> "comman
bars" -> "macros" menu)

Any help is highly appreciated

Sub DisplayFollowUpBarMenus()
Dim myOlApp As Outlook.Application
Dim myItemb As Outlook.MailItem
Dim myInspector As Outlook.Inspector
Dim cmb As CommandBar
Dim insp As Inspector

Set myOlApp = Nothing
Set myItemb = Nothing
Set myInspector = Nothing
Set myOlApp = CreateObject("Outlook.Application")
Set myItemb = myOlApp.CreateItem(olMailItem)
Set myInspector = myItemb.GetInspector

For Each cmb In myInspector.CommandBars
If cmb.Name = "Followup" Then cmb.Delete
Next
Set cb = myInspector.CommandBars.Add(Name:=Followup, _
temporary:=False, Position:=msoBarTop)
cb.Visible = True
Set cbc = cb.Controls.Add(Type:=msoControlButton)
With cbc
.FaceId = 273
.Caption = "morgen"
.Style = msoButtonIconAndCaption
.OnAction = "FUtomorrow"
End With
Set cbc = cb.Controls.Add(Type:=msoControlButton)
With cbc
.FaceId = 273
.Caption = "5"
.OnAction = "FUfivedays"
.Style = msoButtonIconAndCaption
.BeginGroup = True
End With

myInspector.Display
myInspector.Close (olDiscard)
End Su
 
Ad

Advertisements

M

Michael Bauer [MVP - Outlook]

If the purpose is only to create the commandbar, use the NewInspector event.

And if the code runs within Outlook, don't call GetObject or CreateObject,
instead use the instrinsic Application object.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 19 Jan 2010 21:44:59 +0000 schrieb technomane:
 

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