PC Review


Reply
Thread Tools Rate Thread

A button on a toolbar to open a .pst file

 
 
Conan Kelly
Guest
Posts: n/a
 
      10th Jul 2005
Hello all,

I would like to place a button on an existing toolbar that with one click
will open my wife's .pst file and will show that button as pressed, and with
the next click will close/remove her .pst file and show that button as
unpressed.

I found in the help file code to help me open and close the .pst file. I
should be able to get that to work.

The problem I'm having is that it appears the toolbars/buttons are not
objects with events that I can write my code in.

Is there anyway that I can put code in event procedures of buttons on
toolbars?

Thanks for any help anyone can provide,

Conan Kelly


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
Posts: n/a
 
      12th Jul 2005
You can indeed hook into a custom commandbar button. The trick is declaring
the variable to the button using the WithEvents statement, and then you can
trap the Click event and run your custom code.

This code shows how to hook into or create a custom commandbar button when
Outlook starts, and illustrates the use of the button down and up states when
it is clicked:

Option Explicit
Dim WithEvents objLinkedCommandBarButton As Office.CommandBarButton

Private Sub Application_Startup()
CreateCustomButtonWithEventHook
End Sub

Sub CreateCustomButtonWithEventHook()
On Error Resume Next

Dim objCB As Office.CommandBar
Dim objCBB As Office.CommandBarButton

Set objCB = Application.ActiveExplorer.CommandBars("Standard")

'Retrieve a previously created custom commandbar button
Set objCBB = objCB.Controls.Item("My Custom Button")
If objCBB Is Nothing Then
'The commandbar button doesn't exist, create
Set objCBB = objCB.Controls.Add(MsoControlType.msoControlButton, , ,
, False)
With objCBB
.Caption = "My Custom Button"
.State = msoButtonUp
End With
End If

Set objLinkedCommandBarButton = objCBB
End Sub

Private Sub objLinkedCommandBarButton_Click(ByVal Ctrl As
Office.CommandBarButton, CancelDefault As Boolean)
If objLinkedCommandBarButton.State = msoButtonDown Then
objLinkedCommandBarButton.State = msoButtonUp
Else
objLinkedCommandBarButton.State = msoButtonDown
End If
MsgBox "I've been clicked!"
End Sub

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/


"Conan Kelly" wrote:

> Hello all,
>
> I would like to place a button on an existing toolbar that with one click
> will open my wife's .pst file and will show that button as pressed, and with
> the next click will close/remove her .pst file and show that button as
> unpressed.
>
> I found in the help file code to help me open and close the .pst file. I
> should be able to get that to work.
>
> The problem I'm having is that it appears the toolbars/buttons are not
> objects with events that I can write my code in.
>
> Is there anyway that I can put code in event procedures of buttons on
> toolbars?
>
> Thanks for any help anyone can provide,
>
> Conan Kelly
>
>
>

 
Reply With Quote
 
Conan Kelly
Guest
Posts: n/a
 
      12th Jul 2005
Eric,

Thank you for your help. I will try this when I get home.

Conan




"Eric Legault [MVP - Outlook]" <(E-Mail Removed)> wrote in
message news:5498A699-A7C5-42E7-9760-(E-Mail Removed)...
> You can indeed hook into a custom commandbar button. The trick is
> declaring
> the variable to the button using the WithEvents statement, and then you
> can
> trap the Click event and run your custom code.
>
> This code shows how to hook into or create a custom commandbar button when
> Outlook starts, and illustrates the use of the button down and up states
> when
> it is clicked:
>
> Option Explicit
> Dim WithEvents objLinkedCommandBarButton As Office.CommandBarButton
>
> Private Sub Application_Startup()
> CreateCustomButtonWithEventHook
> End Sub
>
> Sub CreateCustomButtonWithEventHook()
> On Error Resume Next
>
> Dim objCB As Office.CommandBar
> Dim objCBB As Office.CommandBarButton
>
> Set objCB = Application.ActiveExplorer.CommandBars("Standard")
>
> 'Retrieve a previously created custom commandbar button
> Set objCBB = objCB.Controls.Item("My Custom Button")
> If objCBB Is Nothing Then
> 'The commandbar button doesn't exist, create
> Set objCBB = objCB.Controls.Add(MsoControlType.msoControlButton, ,
> ,
> , False)
> With objCBB
> .Caption = "My Custom Button"
> .State = msoButtonUp
> End With
> End If
>
> Set objLinkedCommandBarButton = objCBB
> End Sub
>
> Private Sub objLinkedCommandBarButton_Click(ByVal Ctrl As
> Office.CommandBarButton, CancelDefault As Boolean)
> If objLinkedCommandBarButton.State = msoButtonDown Then
> objLinkedCommandBarButton.State = msoButtonUp
> Else
> objLinkedCommandBarButton.State = msoButtonDown
> End If
> MsgBox "I've been clicked!"
> End Sub
>
> --
> Eric Legault - B.A, MCP, MCSD, Outlook MVP
> Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
> Job: http://www.imaginets.com
> Blog: http://blogs.officezealot.com/legault/



 
Reply With Quote
 
Conan Kelly
Guest
Posts: n/a
 
      14th Jul 2005
Eric,

I want to thank you again for the info. I haven't tried yet to get this to
do what I want it to do. But I did paste your code in "as-is" and like how
it works. I'm pretty sure I can get this to do what I want it to.

Usually when I post questions and they don't get answered in a day or two, I
know that they will never get answered. That is what I was expecting with
this question. It seems like no one else wanted to touch this one. But you
came through.

Thanks again,

Conan


"Eric Legault [MVP - Outlook]" <(E-Mail Removed)> wrote in
message news:5498A699-A7C5-42E7-9760-(E-Mail Removed)...
> You can indeed hook into a custom commandbar button. The trick is
> declaring
> the variable to the button using the WithEvents statement, and then you
> can
> trap the Click event and run your custom code.
>
> This code shows how to hook into or create a custom commandbar button when
> Outlook starts, and illustrates the use of the button down and up states
> when
> it is clicked:
>
> Option Explicit
> Dim WithEvents objLinkedCommandBarButton As Office.CommandBarButton
>
> Private Sub Application_Startup()
> CreateCustomButtonWithEventHook
> End Sub
>
> Sub CreateCustomButtonWithEventHook()
> On Error Resume Next
>
> Dim objCB As Office.CommandBar
> Dim objCBB As Office.CommandBarButton
>
> Set objCB = Application.ActiveExplorer.CommandBars("Standard")
>
> 'Retrieve a previously created custom commandbar button
> Set objCBB = objCB.Controls.Item("My Custom Button")
> If objCBB Is Nothing Then
> 'The commandbar button doesn't exist, create
> Set objCBB = objCB.Controls.Add(MsoControlType.msoControlButton, ,
> ,
> , False)
> With objCBB
> .Caption = "My Custom Button"
> .State = msoButtonUp
> End With
> End If
>
> Set objLinkedCommandBarButton = objCBB
> End Sub
>
> Private Sub objLinkedCommandBarButton_Click(ByVal Ctrl As
> Office.CommandBarButton, CancelDefault As Boolean)
> If objLinkedCommandBarButton.State = msoButtonDown Then
> objLinkedCommandBarButton.State = msoButtonUp
> Else
> objLinkedCommandBarButton.State = msoButtonDown
> End If
> MsgBox "I've been clicked!"
> End Sub
>
> --
> Eric Legault - B.A, MCP, MCSD, Outlook MVP
> Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
> Job: http://www.imaginets.com
> Blog: http://blogs.officezealot.com/legault/



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open form from toolbar button kim Microsoft Outlook Form Programming 1 13th Aug 2008 03:52 PM
open an oft. through a toolbar button Zairay@gmail.com Microsoft Outlook Discussion 0 13th Jan 2007 08:59 AM
Open a database from a toolbar button =?Utf-8?B?TmljaG9sYXMgU2NhcnBpbmF0bw==?= Microsoft Access 0 22nd Nov 2005 04:16 PM
Open toolbar button? Tim Wentworth Microsoft Word New Users 1 8th Apr 2005 07:35 AM
How do I put a toolbar button to open a custom form in Outlook? =?Utf-8?B?U3VzYW4=?= Microsoft Outlook VBA Programming 1 19th Feb 2005 09:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 PM.