在 PowerPoint VBA 中创建一个按钮,但它不可点击
Creating a button in PowerPoint VBA, but it's not clickable
我正在 Excel VBA 工作,创建 PowerPoint 演示文稿。
我正在尝试放置 Next 和 [=每张幻灯片上有 17=]上一张 按钮。我正在使用下面的代码:
Dim ppApp As PowerPoint.Application, ppPres As PowerPoint.Presentation, ppSlide As PowerPoint.Slide
Dim shpNextButton As PowerPoint.Shape
Set ppApp = CreateObject("Powerpoint.Application")
Set ppPres = ppApp.Presentations.Open("C:\Users\test1.pptm")
Set ppSlide = ppPres.Slides.Add(ppPres.slides.count + 1, ppLayoutBlank)
Set shpNextButton = ppSlide.Shapes.AddShape(msoShapeActionButtonForwardorNext, 750, 480, 40, 12.5)
With shpNextButton.TextFrame.TextRange
.Text = "Next"
With .Font
.Size = 10
.name = "Arial"
End With
End With
shpNextButton.ActionSettings(ppMouseClick).Action = ppActionNextSlide
这段代码创建了带有正确文本的按钮。但是在 PowerPoint 幻灯片中,该按钮是可单击的。当我点击它时,它就像一个普通的形状。
当我在 PowerPoint VBE 中使用它的改编版本(删除第 1、3、4 行并为第 5 行设置对当前幻灯片的引用)时,你的代码对我有用,所以我唯一能想到的如果您还没有将 PowerPoint 库添加到您的项目中,那么 'pp' 常量不会被设置。如果你输入这个,你会在即时 window 中得到什么?
?ppActionNextSlide
如果一切正常,应该return1。如果它 returns 0 那么这相当于 ppActionNone 这将解释正在发生的事情。
顺便说一句,您的代码在我的 4:3 幻灯片之外添加了按钮,因此我假设您使用的是 16:9 幻灯片布局。最好参考边的右侧少一个偏移量来避免这个潜在的问题:
ActivePresentation.PageSetup.SlideWidth
我正在 Excel VBA 工作,创建 PowerPoint 演示文稿。
我正在尝试放置 Next 和 [=每张幻灯片上有 17=]上一张 按钮。我正在使用下面的代码:
Dim ppApp As PowerPoint.Application, ppPres As PowerPoint.Presentation, ppSlide As PowerPoint.Slide
Dim shpNextButton As PowerPoint.Shape
Set ppApp = CreateObject("Powerpoint.Application")
Set ppPres = ppApp.Presentations.Open("C:\Users\test1.pptm")
Set ppSlide = ppPres.Slides.Add(ppPres.slides.count + 1, ppLayoutBlank)
Set shpNextButton = ppSlide.Shapes.AddShape(msoShapeActionButtonForwardorNext, 750, 480, 40, 12.5)
With shpNextButton.TextFrame.TextRange
.Text = "Next"
With .Font
.Size = 10
.name = "Arial"
End With
End With
shpNextButton.ActionSettings(ppMouseClick).Action = ppActionNextSlide
这段代码创建了带有正确文本的按钮。但是在 PowerPoint 幻灯片中,该按钮是可单击的。当我点击它时,它就像一个普通的形状。
当我在 PowerPoint VBE 中使用它的改编版本(删除第 1、3、4 行并为第 5 行设置对当前幻灯片的引用)时,你的代码对我有用,所以我唯一能想到的如果您还没有将 PowerPoint 库添加到您的项目中,那么 'pp' 常量不会被设置。如果你输入这个,你会在即时 window 中得到什么?
?ppActionNextSlide
如果一切正常,应该return1。如果它 returns 0 那么这相当于 ppActionNone 这将解释正在发生的事情。
顺便说一句,您的代码在我的 4:3 幻灯片之外添加了按钮,因此我假设您使用的是 16:9 幻灯片布局。最好参考边的右侧少一个偏移量来避免这个潜在的问题:
ActivePresentation.PageSetup.SlideWidth