使用PowerPoint对象库15.0的代码不能在具有库14.0的计算机上工作
我有一个VBAmacros从Excel中的行创build一个PPT甲板。 它在我的电脑上运行效果很好(使用PowerPoint Object Library 15.0),但是当分发给具有较旧PowerPoint对象库(例如14.0)的用户时,它将会粘贴粘贴形状的格式。
我读了早期/晚期的约束,不知道如何解决这个问题。 如何更改我的代码以使用早期绑定而不是晚期绑定? 其他相关的问题,我发现没有答案。
使用早期绑定来编写代码,这样更容易。 完成后,将其更改为迟装。
早期绑定:检查参考(工具 – >参考)到Ms PowerPoint 15.0对象库。
Dim pptApp As PowerPoint.Application Dim pptPres As PowerPoint.Presentation Dim pptSlide As PowerPoint.Slide Set pptApp = CreateObject("Powerpoint.Application") Set pptPres = pptApp.Presentations.Add Set pptSlide = pptPres.Slides.Add(1, ppLayoutTwoObjects)
后期绑定:删除对PP15对象库的引用。
Dim pptApp As Object Dim pptPres As Object Dim pptSlide As Object Set pptApp = CreateObject("Powerpoint.Application") Set pptPres = pptApp.Presentations.Add Set pptSlide = pptPres.Slides.Add(1, 29)
请注意,在后期绑定中,不能使用内置常量,例如。 ppLayoutTwoObjects。 你将不得不使用他们的数值。
你可以阅读更多关于早期VS晚期绑定在这里: http : //word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm
要使用延迟绑定,请在VBA IDE中进入工具 – >参考并取消选中Powerpoint条目。 这将从编译器中删除Powerpoint对象模型和常量的所有知识。 您将需要将提及Powerpoint对象的任何Dim
语句更改为Object
,例如:
Dim mySlide As Slide
至
Dim mySlide As Object
如果您在此代码中使用任何常量,例如msoTextOrientationHorizontal
:
ActivePresentation.Slides(1).Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _ Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _ .TextRange.Text = "Test Box"
您将需要用数字值replace常量。
ActivePresentation.Slides(1).Shapes.AddTextbox(Orientation:=1, _ Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _ .TextRange.Text = "Test Box"