【问题标题】:How to make a toggle button in a commandbar VBA PowerPoint?如何在命令栏 VBA PowerPoint 中制作切换按钮?
【发布时间】: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

【问题讨论】:

标签: vba powerpoint


【解决方案1】:

我需要将 Toggle True 添加到“Else”一侧

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

RemoveBleed

Else

With Application.CommandBars.ActionControl 'unpresses the button
 .State = Not .State
End With
 Toggle = True 'changes the variable so next time it operates the other macro


AddBleed

End If

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2020-12-27
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2015-10-19
    相关资源
    最近更新 更多