VBA: 在 PowerPoint 中添加文本框并将其分配给对象变量
VBA: Add textbox in PowerPoint and assign it to object variable
我可以在 PowerPoint 中向幻灯片添加文本框,但如果我尝试将其分配给变量,则会出现错误 13:类型不匹配。我究竟做错了什么?
Sub Test()
Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim shpTxtBox As Shape
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT) 'this works, I'm just not gonna write out the path of the presentation
Set mySlide = myPresentation.Slides.Add(myPresentation.Slides.Count - 14, 12)
'mySlide.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60 '<---- works
Set shpTxtBox = mySlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60) '<-----doesn't work
End Sub
您的声明会导致类型不匹配。
Dim shpTxtBox As Shape <- this is an Excel shape, not a Powerpoint one.
修复:
Dim shpTxtBox as Powerpoint.Shape
我可以在 PowerPoint 中向幻灯片添加文本框,但如果我尝试将其分配给变量,则会出现错误 13:类型不匹配。我究竟做错了什么?
Sub Test()
Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim shpTxtBox As Shape
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT) 'this works, I'm just not gonna write out the path of the presentation
Set mySlide = myPresentation.Slides.Add(myPresentation.Slides.Count - 14, 12)
'mySlide.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60 '<---- works
Set shpTxtBox = mySlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60) '<-----doesn't work
End Sub
您的声明会导致类型不匹配。
Dim shpTxtBox As Shape <- this is an Excel shape, not a Powerpoint one.
修复:
Dim shpTxtBox as Powerpoint.Shape