Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a Outlook startup macro that adds buttons to a toolbar

Status
Not open for further replies.

daglugub37

Technical User
Oct 21, 2003
201
US
I like the "File | Exit and Logoff" and "Edit | Mark as Unread" buttons available on my standard inbox toolbar.

However each time I open a new session of Outlook 2000 running on Exchange 2000, the buttons i added disappear.

I can not figure out why, internet searches lean towards an unresolved bug.

Instead of manually adding them back each day I would like to write a start up macro which adds them for me.

Can you help?
 
Look in help under CommnadBars collection and Add method. Hopefully that will at least get you started. I have some code at home I'll try to remember to post later. Good Luck!

Have a great day!

j2consulting@yahoo.com
 
Thanks,

I am checking out the help files, but VBA is above me and am not quite sure where to begin. I will mess around and keep an eye out for another post from you.

much appreciated
 
Hello daglugub37,

Sorry I wasn't able to get back more quickly, the last couple days have been pretty long. Here is some code to help get you started.

Since it sounds like you have already written your macros, here is how you automate the process. Since you said you aren't real comfortable with VBA, this is step by step.

A. From standard Outlook, Click Tools, Macro, Visual Basic Editor (or Alt+F11).

B. How the editor appears can vary depending on various settings and user actions, so to ensure the proper pieces are visible, Click on View, Project Explorer (or Ctrl+R). The Project Explorer displays similarly to the folders in the File Browser, click a + sign to open it up. Click on any + signs you see so everything is available to you.

C. To add your macro code to Outlook so it will load automatically for you, Right click on ThisOutlookSession and select View Code or DoubleClick it. This will open up the code editor.

D. At the top you will see 2 drop down comboboxes. The one on the left will probably say (General) and the one on the right will say (Declarations). Click the drop down arrow on the left combobox and select Application. The combobox on the right will change to display all of the events available to you. If it created a little bit of code for you, don't worry about it for now.

E. Click the drop down arrow on the right combobox and select Startup. It will create a sub routine declaration for you as follows (Note: I added 'Put your code here).

Code:
Private Sub Application_Startup()
    'Put your code here
End Sub

F. Place your macro code as noted above and it will be executed every time Outlook starts.

G. You can now go back and delete any similar code it created for you that you don't need.

I hope this helps. Please feel free to post again if you have more questions.

If you want to or need to add some custom buttons to your toolbars here is an example showing you how to do that. Click Insert, Module on the Insert menu and copy the following code into it. You can single step through the code by clicking anywhere in the code and then pressing F8 repeatedly. F5 will run it all the way through.

A. This code will loop through the highest level of command bars and show their names if they are visible. This list corresponds to checked items you see if you click View, Toolbars on your menu.

Code:
Sub TestIt()
Dim obj As Object
    For Each obj In Application.CommandBars
        If obj.Visible Then
            MsgBox obj.Name & " " & obj.Visible & " " & obj.RowIndex
            'lists in immediate window
            Debug.Print obj.Name & " " & obj.Visible & " " & obj.RowIndex
    End If
    Next obj
    Set obj = Nothing
End Sub

To see the Immediate Window, while in the VB Editor click View, Immediate Window (Ctrl+G)

B. Use the results from A above if you want to display your custom toolbar on the same line as an existing one. For purposes of discussion, let's say you wanted to display it on the same line as the formatting toolbar if it is visible. The temporary options tell the system to delete the toolbars when you close Outlook. They are recreated every time.

Code:
SubTestIt2()
Dim lngRowIndex As Long
    On Error Resume Next
    With Application
        If .CommandBars("Formatting").Visible Then
            lngRowIndex = .CommandBars("Formatting").RowIndex
        Else
            lngRowIndex = .CommandBars.Count + 1
        End If
    End With

    'Next 3 lines add an empty custom ToolBar and make it visible
    With CommandBars.Add("YourCustomName", msoBarTop, False, Temporary:=True)
        .RowIndex = lngRowIndex
        .Visible = True

        'This code adds a CommandBar Button
        With .Controls.Add(msoControlButton, Temporary:=True)
            .DescriptionText = "Inserts a new payroll row for the active worksheet"
            .Style = msoButtonCaption
            .Caption = "&New Payroll"
            .TooltipText = "Insert a new payroll line in current worksheet"
            .OnAction = "YourCustomAction"
        End With
    End With
    On Error GoTo 0
End Sub

Code:
'Private sub routine which corresponds to OnAction above
'This code is executed when CommandBar Control added above is clicked
Private Sub YourCustomAction()
    MsgBox "YourCustomAction"
End Sub

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top