Как сделать кнопку переключения в командной строке VBA PowerPoint? - PullRequest
0 голосов
/ 12 марта 2020

Я пытаюсь сделать кнопку переключения на панели команд, но я сталкиваюсь с двумя проблемами 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

1 Ответ

0 голосов
/ 12 марта 2020

Мне нужно было добавить Toggle True в сторону «Остальное»

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...