PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming A button on a toolbar to open a .pst file

Reply

A button on a toolbar to open a .pst file

 
Thread Tools Rate Thread
Old 10-07-2005, 07:24 PM   #1
Conan Kelly
Guest
 
Posts: n/a
Default A button on a toolbar to open a .pst file


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
Old 12-07-2005, 08:14 PM   #2
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
 
Posts: n/a
Default RE: A button on a toolbar to open a .pst file

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
Old 12-07-2005, 08:35 PM   #3
Conan Kelly
Guest
 
Posts: n/a
Default Re: A button on a toolbar to open a .pst file

Eric,

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

Conan




"Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
message news:5498A699-A7C5-42E7-9760-513B62863D36@microsoft.com...
> 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
Old 14-07-2005, 10:23 PM   #4
Conan Kelly
Guest
 
Posts: n/a
Default Re: A button on a toolbar to open a .pst file

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]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
message news:5498A699-A7C5-42E7-9760-513B62863D36@microsoft.com...
> 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

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