3

.Caption下面的代码和顶部的图标缺少什么?

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

使用msoButtonIconAndCaptionBelow按钮样式,它不应该像我想要的那样吗?

4

1 回答 1

2

问题可能与图片有关。您需要使用 16x16 和 256 色的 BMP(请参阅此知识库文章)。请注意,您还可以为此设置遮罩以提高透明度。

但是,从您上面的评论来看,您似乎希望在 PowerPoint 2007 中执行此操作。如果您希望在 Office 2007/2010 中执行此操作,则不应再使用 CommandBar 对象,而应使用 Ribbon 技术。是一篇非常好的文章。如果您使用 VBA,自定义功能区编辑器是必不可少的,这里有一个很棒的登录页面,可以帮助您开始使用带有 VBA 的 RibbonX(示例适用于 Excel 2007,但在 PPT/WRD 中也是如此)。

于 2010-02-28T08:14:54.993 回答