【发布时间】:2020-03-13 02:53:18
【问题描述】:
我正在尝试在命令栏上创建一个切换按钮,但我遇到了两个问题 1) 它一直在执行“removebleed”,而不是在两者之间切换。 2)它不显示正在切换的按钮。首先,我附上了菜单按钮代码,然后是按钮代码。非常感谢您的帮助,杰伊
Set ToggleButton = oToolbar.Controls.Add(Type:=msoControlButton)
With ToggleButton
.DescriptionText = "Switch bleed on or off"
.Caption = "Bleed on/off"
.OnAction = "ToggleButton"
.Style = msoButtonCaption
End With
Sub ToggleButton()
Static Toggle As Boolean
If Toggle = True Then
With Application.CommandBars.ActionControl
.State = Not .State
End With
Toggle = False ' changes the variable so next time it unpresses the button and runs the other macro
AddBleed
Else
RemoveBleed
End If
End Sub
Sub AddBleed()
Dim WidthBleed As String
Dim HeightBleed As String
WidthBleed = 0.125 * 72
HeightBleed = 0.25 * 72
SWidth = ActivePresentation.PageSetup.SlideWidth
SHeight = ActivePresentation.PageSetup.SlideHeight
With Application.ActivePresentation.PageSetup
.SlideWidth = SWidth + WidthBleed
.SlideHeight = SHeight + HeightBleed
End With
End Sub
Sub RemoveBleed()
Dim WidthBleed As String
Dim HeightBleed As String
Dim SWidth As String
Dim SHeight As String
WidthBleed = 0.125 * 72
HeightBleed = 0.25 * 72
SWidth = ActivePresentation.PageSetup.SlideWidth
SHeight = ActivePresentation.PageSetup.SlideHeight
With Application.ActivePresentation.PageSetup
.SlideWidth = SWidth - WidthBleed
.SlideHeight = SHeight - HeightBleed
End With
End Sub
【问题讨论】:
-
命令栏已过时,它们曾在 Office 2003 中使用。保留 VBA 是为了向后兼容。创建命令栏的旧宏会将控件重新路由到 PowerPoint 中的“加载项”选项卡,而不是显示为真正的命令栏。相反,请考虑修改 RibbonUI。这是来自 Microsoft 网站的介绍性文章:docs.microsoft.com/en-us/office/vba/library-reference/concepts/…。这是一个 RibbonUI 编辑器,这使工作更容易:github.com/fernandreu/office-ribbonx-editor
标签: vba powerpoint