views:

148

answers:

1

What's missing in the following code, for the .Caption gets bellow and the icon on the top?

Sub SoundLogToolbar()
    Dim cb As CommandBar
    Dim de As CommandBar
    Dim but As CommandBarButton
    Dim picPicture As IPictureDisp

    On Error Resume Next
        MkDir "C:\SoundLog\"
    On Error GoTo 0

    On Error Resume Next
        MkDir "C:\SoundLog\Presentations\"
    On Error GoTo 0

    Set picPicture = stdole.StdFunctions.LoadPicture("C:\SoundLog\Presentations\SoundLog.gif")

    On Error Resume Next
        Application.CommandBars("SoundLog").Delete
    On Error GoTo 0

    Set cb = Application.CommandBars.Add("SoundLog", msoBarTop, , True)

    Set but = CommandBars("SoundLog").Controls.Add(msoControlButton)
    but.Visible = True
    With but
        .Picture = picPicture
        .OnAction = "ShowUserForm"
        .Caption = "SoundLog!"
        .TooltipText = "run this to get data!"
        .Style = msoButtonIconAndCaptionBelow
    End With

    cb.Visible = True
End Sub

With the msoButtonIconAndCaptionBelow button style, it wasn't suppose to be like I want?

+1  A: 

The issue is likely with the picture. You need to use a BMP of 16x16 with 256 colors (see this KB article). Note you can also set a mask on this for transparency.

From your comment above, however, it looks like you are wanting to do this for PowerPoint 2007. If you are wanting to do this in Office 2007/2010, you shouldn't be using the CommandBar object anymore and rather using the Ribbon technology. Here's a really good article on this. If you're using VBA, the Custom Ribbon Editor is indispensible and here's a great landing page to get you started with RibbonX with VBA (examples are for Excel 2007, but it's the same in PPT/WRD).

Otaku