Crash when using GetInspector
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:
Hello all,
hope you can help me with my problem here. The following code crashes
at line "Set myInspector = myItemb.GetInspector" (Outlook completely
crashes and needs to restart). I have no idea why this happens. From
what I've tried, it only crashes when the macro is started right after
OL startup, while no inspector item was yet launched. When I click on
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 to
every new inspector item (like you would do via "customize" - "command
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 Sub
|