![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi,
I want to add a command bar to the contact window as soon as it opens. This command bar shall not display on mail or task windows. Is there an event to trigger the macro or how can I achieve it? Thanks Willem |
#2
|
|||
|
|||
![]()
In the NewInspector event of the Inspectors collection check for
Inspector.CurrentItem.Class = olContact. If that is true then create your button. I would most likely use the Inspector.Activate event to create the button, setting a flag so the create code only runs on the first Activate. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Willem Peper" wrote in message ... Hi, I want to add a command bar to the contact window as soon as it opens. This command bar shall not display on mail or task windows. Is there an event to trigger the macro or how can I achieve it? Thanks Willem |
#3
|
|||
|
|||
![]()
Use the Inspectors.NewInspector event and check the value of Inspector.CurrentItem.Class to determine what type of item was opened.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Willem Peper" wrote in message ... Hi, I want to add a command bar to the contact window as soon as it opens. This command bar shall not display on mail or task windows. Is there an event to trigger the macro or how can I achieve it? Thanks Willem |
#4
|
|||
|
|||
![]()
Sue and Ken
Thank you for your advice. I put some code together which still has problems. If I start Outlook and open a contact the addMyMenu is called but results in a runtime error '91' object variable or with-block variable are missing. If I start addMyMenu manually from the open contact it adds the popup menu as requested. What#s the fault? Please check my code. Thanks Willem VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "DieseOutlookSitzung" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Option Explicit Public myOlApp As New Outlook.Application Public WithEvents myOlInspectors As Outlook.Inspectors Attribute myOlInspectors.VB_VarHelpID = -1 Private Sub Application_Startup() Set myOlInspectors = myOlApp.Inspectors End Sub Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) If Inspector.CurrentItem.Class = olContact Then addMyMenu End If End Sub Public Sub addMyMenu() Dim OlApp As Outlook.Application Dim colCB As Office.CommandBars Dim objCB As Office.CommandBar Dim objCBMenu As Office.CommandBarPopup Dim objCBMenuCB As Office.CommandBar Dim objCBB As Office.CommandBarButton Set OlApp = CreateObject("Outlook.Application") Set colCB = OlApp.ActiveInspector.CommandBars '***** Runtime error '91' Set objCB = colCB.Item("Menu Bar") Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True) With objCBMenu .Caption = "Spezial" Set objCBMenuCB = .CommandBar Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Besuchsbericht" objCBB.OnAction = "erfassKontakt2" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Kontakt kopieren" objCBB.OnAction = "copy_contact_info" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Angebot" objCBB.OnAction = "Angebotsanfrage" End With Set OlApp = Nothing Set colCB = Nothing Set objCB = Nothing Set objCBMenu = Nothing Set objCBMenuCB = Nothing Set objCBB = Nothing End Sub |
#5
|
|||
|
|||
![]()
Use the intrinsic Application object (the one you invoke with the Application_Startup event handler). Don't create a new one with CreateObject.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Willem Peper" wrote in message ... Sue and Ken Thank you for your advice. I put some code together which still has problems. If I start Outlook and open a contact the addMyMenu is called but results in a runtime error '91' object variable or with-block variable are missing. If I start addMyMenu manually from the open contact it adds the popup menu as requested. What#s the fault? Please check my code. Thanks Willem VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "DieseOutlookSitzung" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Option Explicit Public myOlApp As New Outlook.Application Public WithEvents myOlInspectors As Outlook.Inspectors Attribute myOlInspectors.VB_VarHelpID = -1 Private Sub Application_Startup() Set myOlInspectors = myOlApp.Inspectors End Sub Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) If Inspector.CurrentItem.Class = olContact Then addMyMenu End If End Sub Public Sub addMyMenu() Dim OlApp As Outlook.Application Dim colCB As Office.CommandBars Dim objCB As Office.CommandBar Dim objCBMenu As Office.CommandBarPopup Dim objCBMenuCB As Office.CommandBar Dim objCBB As Office.CommandBarButton Set OlApp = CreateObject("Outlook.Application") Set colCB = OlApp.ActiveInspector.CommandBars '***** Runtime error '91' Set objCB = colCB.Item("Menu Bar") Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True) With objCBMenu .Caption = "Spezial" Set objCBMenuCB = .CommandBar Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Besuchsbericht" objCBB.OnAction = "erfassKontakt2" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Kontakt kopieren" objCBB.OnAction = "copy_contact_info" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Angebot" objCBB.OnAction = "Angebotsanfrage" End With Set OlApp = Nothing Set colCB = Nothing Set objCB = Nothing Set objCBMenu = Nothing Set objCBMenuCB = Nothing Set objCBB = Nothing End Sub |
#6
|
|||
|
|||
![]()
Sorry,
but it doesn't fix the problem. In the mean time I played around with the blocking line and got following results. ActiveExplorer and activeWindow work if triggere by opening a contact but put the new menu in the wrong command bar. Set colCB = myOlApp.ActiveExplorer.CommandBars ' triggered: new menu in the main command bar / Manually: new menu in the main command bar Set colCB = myOlApp.ActiveWindow.CommandBars 'triggered: new menu in the main command bar / Manually: new menu in the contact command bar Set colCB = myOlApp.ActiveInspector.CommandBars 'triggered: Runtime error '91' / Manually: new menu in the contact command bar Why does ActiveExplorer not work? Regards Willem "Sue Mosher [MVP-Outlook]" schrieb im Newsbeitrag ... Use the intrinsic Application object (the one you invoke with the Application_Startup event handler). Don't create a new one with CreateObject. "Willem Peper" wrote in message ... Sue and Ken Thank you for your advice. I put some code together which still has problems. If I start Outlook and open a contact the addMyMenu is called but results in a runtime error '91' object variable or with-block variable are missing. If I start addMyMenu manually from the open contact it adds the popup menu as requested. What#s the fault? Please check my code. Thanks Willem VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "DieseOutlookSitzung" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Option Explicit Public myOlApp As New Outlook.Application Public WithEvents myOlInspectors As Outlook.Inspectors Attribute myOlInspectors.VB_VarHelpID = -1 Private Sub Application_Startup() Set myOlInspectors = myOlApp.Inspectors End Sub Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) If Inspector.CurrentItem.Class = olContact Then addMyMenu End If End Sub Public Sub addMyMenu() Dim OlApp As Outlook.Application Dim colCB As Office.CommandBars Dim objCB As Office.CommandBar Dim objCBMenu As Office.CommandBarPopup Dim objCBMenuCB As Office.CommandBar Dim objCBB As Office.CommandBarButton Set OlApp = CreateObject("Outlook.Application") Set colCB = OlApp.ActiveInspector.CommandBars '***** Runtime error '91' Set objCB = colCB.Item("Menu Bar") Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True) With objCBMenu .Caption = "Spezial" Set objCBMenuCB = .CommandBar Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Besuchsbericht" objCBB.OnAction = "erfassKontakt2" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Kontakt kopieren" objCBB.OnAction = "copy_contact_info" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Angebot" objCBB.OnAction = "Angebotsanfrage" End With Set OlApp = Nothing Set colCB = Nothing Set objCB = Nothing Set objCBMenu = Nothing Set objCBMenuCB = Nothing Set objCBB = Nothing End Sub |
#7
|
|||
|
|||
![]()
I would never use ActiveWIndow.CommandBars, only ActiveExplorer.CommandBars or ActiveInspector.CommandBars.
I'm now confused, though, about what's not working and what ActiveExplorer has to do with this at all./ -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Willem Peper" wrote in message ... Sorry, but it doesn't fix the problem. In the mean time I played around with the blocking line and got following results. ActiveExplorer and activeWindow work if triggere by opening a contact but put the new menu in the wrong command bar. Set colCB = myOlApp.ActiveExplorer.CommandBars ' triggered: new menu in the main command bar / Manually: new menu in the main command bar Set colCB = myOlApp.ActiveWindow.CommandBars 'triggered: new menu in the main command bar / Manually: new menu in the contact command bar Set colCB = myOlApp.ActiveInspector.CommandBars 'triggered: Runtime error '91' / Manually: new menu in the contact command bar Why does ActiveExplorer not work? Regards Willem "Sue Mosher [MVP-Outlook]" schrieb im Newsbeitrag ... Use the intrinsic Application object (the one you invoke with the Application_Startup event handler). Don't create a new one with CreateObject. "Willem Peper" wrote in message ... Sue and Ken Thank you for your advice. I put some code together which still has problems. If I start Outlook and open a contact the addMyMenu is called but results in a runtime error '91' object variable or with-block variable are missing. If I start addMyMenu manually from the open contact it adds the popup menu as requested. What#s the fault? Please check my code. Thanks Willem VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "DieseOutlookSitzung" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Option Explicit Public myOlApp As New Outlook.Application Public WithEvents myOlInspectors As Outlook.Inspectors Attribute myOlInspectors.VB_VarHelpID = -1 Private Sub Application_Startup() Set myOlInspectors = myOlApp.Inspectors End Sub Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) If Inspector.CurrentItem.Class = olContact Then addMyMenu End If End Sub Public Sub addMyMenu() Dim OlApp As Outlook.Application Dim colCB As Office.CommandBars Dim objCB As Office.CommandBar Dim objCBMenu As Office.CommandBarPopup Dim objCBMenuCB As Office.CommandBar Dim objCBB As Office.CommandBarButton Set OlApp = CreateObject("Outlook.Application") Set colCB = OlApp.ActiveInspector.CommandBars '***** Runtime error '91' Set objCB = colCB.Item("Menu Bar") Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True) With objCBMenu .Caption = "Spezial" Set objCBMenuCB = .CommandBar Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Besuchsbericht" objCBB.OnAction = "erfassKontakt2" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Kontakt kopieren" objCBB.OnAction = "copy_contact_info" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Angebot" objCBB.OnAction = "Angebotsanfrage" End With Set OlApp = Nothing Set colCB = Nothing Set objCB = Nothing Set objCBMenu = Nothing Set objCBMenuCB = Nothing Set objCBB = Nothing End Sub |
#8
|
|||
|
|||
![]()
The inspector for the selected customer was not active. after declaring
myItem as Contactitem with events and moving the command bar handling to myItem_read everything seems to work. and if anybody is interessted, here is the working code which has to be place in ThisOutlookSession. Regards Willem Option Explicit Public myOlApp As New Outlook.Application Public WithEvents myOlInspectors As Outlook.Inspectors Public WithEvents myItem As Outlook.ContactItem Private Sub Application_Startup() Set myOlInspectors = myOlApp.Inspectors End Sub Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) If Inspector.CurrentItem.Class = olContact Then Set myItem = Inspector.CurrentItem End If End Sub Private Sub myItem_Read() addMyMenu End Sub Public Sub addMyMenu() Dim colCB As Office.CommandBars Dim objCB As Office.CommandBar Dim objCBMenu As Office.CommandBarPopup Dim objCBMenuCB As Office.CommandBar Dim objCBB As Office.CommandBarButton Set colCB = myOlApp.ActiveInspector.CommandBars Set objCB = colCB.Item("Menu Bar") Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, Temporary:=True) With objCBMenu .Caption = "Spezial" Set objCBMenuCB = .CommandBar Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Besuchsbericht" objCBB.OnAction = "erfassKontakt2" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Kontakt kopieren" objCBB.OnAction = "copy_contact_info" Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True) objCBB.Caption = "Angebot" objCBB.OnAction = "Angebotsanfrage" End With Set myOlApp = Nothing Set colCB = Nothing Set objCB = Nothing Set objCBMenu = Nothing Set objCBMenuCB = Nothing Set objCBB = Nothing End Sub |
#9
|
|||
|
|||
![]()
I forgot to mention that I use Outlook 2002 and Excel/Word 2000 on XP SP2.
Regards Willem |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
OL2003 - can you auto-fill a singel new contact form with online form data | TimR | Outlook - Using Contacts | 1 | February 15th 06 01:43 PM |
opening new mail message form | Melbin | Outlook - Using Forms | 1 | January 24th 06 12:17 PM |
opening new custom Message form | Melbin | Outlook - Using Forms | 2 | January 24th 06 12:16 PM |
form and event click | ivanoe | Outlook - Using Forms | 1 | January 17th 06 08:40 PM |
How to handling Custom Form Control Event in VB Com Add-In? | Raphaël ZHOU \(Jadiam\) | Outlook - Using Forms | 1 | January 11th 06 07:31 AM |