A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Activate button when select contact



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 14th 06, 10:41 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 1
Default Activate button when select contact

I'm building a contact export. I have a macro which checks if the
button exist, if not it create one else it's activate the button when a
contact is selected.
I run this macro manually, but I want to automatic run the macro when
anything is selected. Can anyone tell me how this is possible.

An other problem I have, when I deselect something the button must be
inactive. Like the standard button's in the outlook toolbar.

this is the macro:

Public Sub TMSButton()
Dim oButton As CommandBarControl
Dim objCommandbars As CommandBars
Dim objCommandBar As CommandBar
Dim objCommandBarControl As CommandBarControl
Dim chckExist As Boolean
Dim chckActiveWindow As Object
Dim button

Set objCommandbars = Outlook.ActiveExplorer.CommandBars
Set objCommandBar = objCommandbars.Item("Standard")
Set chckActiveWindow = GetCurrentItem()
chckExist = False

' Check if button exist
For Each objCommandBarControl In objCommandBar.Controls
If objCommandBarControl.Caption = "Export naar TMS" Then
objCommandBar.Controls.Item("Export naar TMS").Enabled =
False
objCommandBar.Controls.Item("Export naar TMS").TooltipText
= "http://tms.conclusion.nl/"
' activate button
If chckActiveWindow.Class = olContact Then
button = activateButton()
End If
chckExist = True
End If
Next objCommandBarControl

' Create button
If chckExist = False Then
button = createButton(chckActiveWindow)
End If

Set chckActiveWindow = Nothing
Set objBar = Nothing
End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem =
objApp.ActiveExplorer.Selection.Item(1)
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
Set objApp = Nothing
End Function

Function createButton(chckActiveWindow)
Dim objButton As Office.CommandBarButton
Dim objBar As Office.CommandBar

Set objBar = ActiveExplorer.CommandBars("Standard")

If chckActiveWindow.Class = olContact Then
Set objButton = objBar.Controls.Add(msoControlButton)
With objButton
.Caption = "Export naar TMS"
.Tag = "TMS Export"
.HyperlinkType = msoCommandBarButtonHyperlinkOpen
.Visible = True
.TooltipText = "http://tms.conclusion.nl"
.Enabled = True
End With
Else
Set objButton = objBar.Controls.Add(msoControlButton)
With objButton
.Caption = "Export naar TMS"
.Tag = "TMS Export"
.HyperlinkType = msoCommandBarButtonHyperlinkOpen
.Visible = True
.TooltipText = "http://tms.conclusion.nl"
.Enabled = False
End With
End If
Set objButton = Nothing
End Function

Function activateButton()
Dim objCommandbars As CommandBars
Dim objCommandBar As CommandBar

Set objCommandbars = Outlook.ActiveExplorer.CommandBars
Set objCommandBar = objCommandbars.Item("Standard")

objCommandBar.Controls.Item("Export naar TMS").Enabled = True
objCommandBar.Controls.Item("Export naar TMS").TooltipText =
"http://tms.conclusion.nl/"

End Function

  #2  
Old June 14th 06, 07:24 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Activate button when select contact

You can use the SelectionChange event for an Explorer object to trap when the
selection of items in a folder has changed. To deactivate a commandbar
button, set the Enabled property to False.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


" wrote:

I'm building a contact export. I have a macro which checks if the
button exist, if not it create one else it's activate the button when a
contact is selected.
I run this macro manually, but I want to automatic run the macro when
anything is selected. Can anyone tell me how this is possible.

An other problem I have, when I deselect something the button must be
inactive. Like the standard button's in the outlook toolbar.

this is the macro:

Public Sub TMSButton()
Dim oButton As CommandBarControl
Dim objCommandbars As CommandBars
Dim objCommandBar As CommandBar
Dim objCommandBarControl As CommandBarControl
Dim chckExist As Boolean
Dim chckActiveWindow As Object
Dim button

Set objCommandbars = Outlook.ActiveExplorer.CommandBars
Set objCommandBar = objCommandbars.Item("Standard")
Set chckActiveWindow = GetCurrentItem()
chckExist = False

' Check if button exist
For Each objCommandBarControl In objCommandBar.Controls
If objCommandBarControl.Caption = "Export naar TMS" Then
objCommandBar.Controls.Item("Export naar TMS").Enabled =
False
objCommandBar.Controls.Item("Export naar TMS").TooltipText
= "http://tms.conclusion.nl/"
' activate button
If chckActiveWindow.Class = olContact Then
button = activateButton()
End If
chckExist = True
End If
Next objCommandBarControl

' Create button
If chckExist = False Then
button = createButton(chckActiveWindow)
End If

Set chckActiveWindow = Nothing
Set objBar = Nothing
End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem =
objApp.ActiveExplorer.Selection.Item(1)
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
Set objApp = Nothing
End Function

Function createButton(chckActiveWindow)
Dim objButton As Office.CommandBarButton
Dim objBar As Office.CommandBar

Set objBar = ActiveExplorer.CommandBars("Standard")

If chckActiveWindow.Class = olContact Then
Set objButton = objBar.Controls.Add(msoControlButton)
With objButton
.Caption = "Export naar TMS"
.Tag = "TMS Export"
.HyperlinkType = msoCommandBarButtonHyperlinkOpen
.Visible = True
.TooltipText = "http://tms.conclusion.nl"
.Enabled = True
End With
Else
Set objButton = objBar.Controls.Add(msoControlButton)
With objButton
.Caption = "Export naar TMS"
.Tag = "TMS Export"
.HyperlinkType = msoCommandBarButtonHyperlinkOpen
.Visible = True
.TooltipText = "http://tms.conclusion.nl"
.Enabled = False
End With
End If
Set objButton = Nothing
End Function

Function activateButton()
Dim objCommandbars As CommandBars
Dim objCommandBar As CommandBar

Set objCommandbars = Outlook.ActiveExplorer.CommandBars
Set objCommandBar = objCommandbars.Item("Standard")

objCommandBar.Controls.Item("Export naar TMS").Enabled = True
objCommandBar.Controls.Item("Export naar TMS").TooltipText =
"http://tms.conclusion.nl/"

End Function


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how not to select a outside line when dialing from contact simonq Outlook - Using Contacts 1 March 31st 06 03:59 PM
For email searches, I should be able to select by Outlook contact JJB-BBall Outlook - Using Contacts 9 February 24th 06 04:16 PM
How to stop Contact Select from showing fax phone? Foolontheroof Outlook - Using Contacts 2 February 23rd 06 01:17 AM
Contact button at the bottom of contact window. Mr D O T Outlook - Using Contacts 2 February 7th 06 10:39 PM
Making a Contact into a shortcut button Simon Outlook - Using Contacts 2 January 19th 06 03:12 PM


All times are GMT +1. The time now is 09:15 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.