作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我继承了一些使用三个全局变量的代码
Global PPTApp As PowerPoint.Application
Global PPTPres As PowerPoint.Presentation
Global PPtSlides As PowerPoint.Slide
稍后在代码中按以下方式使用它们
Sub PasteTablesPPT(TargetText As String, PPTRange As Range)
Dim TargetSlide As PowerPoint.Slide
PPTApp.Activate
For Each PPtSlides In PPTPres.Slides 'Error on colleagues PC
With PPtSlides.Shapes.Title.TextFrame
If .HasText Then
If UCase(.TextRange.Text) = UCase(TargetText) Then
TargetNum = CInt(PPtSlides.SlideIndex)
Exit For
End If
End If
End With
Next
在我的电脑上,这按其应有的方式工作,即它激活打开的 powerpoint 应用程序,然后循环播放该演示文稿中的每张幻灯片。
但是,在我的同事电脑上,我标记的线路上出现了错误。具体错误为Error 451 我认为这与 PPtSlides 未被识别为 PPtPres.Slides 的一部分有关。同样在 Debug模式下,当我将鼠标悬停在 PPtSlides 上时,它显示“Nothing”。
我们在 VBA 工具中进行了相同的引用检查,谁能解释一下为什么这适用于我的电脑而不是我的同事?
编辑:定义 PPTPres 的部分(在另一个子中,这只是该子的摘录)
On Error GoTo ErrHandler
Set PPTApp = GetObject(class:="PowerPoint.Application")
PPTApp.Visible = msoTrue
Set PPTPres = PPTApp.Presentations("Testing File")
Exit Sub
最佳答案
在子 PasteTablesPPT 中,尝试将 PPtSlides 声明为 PowerPoint.Slide
dim PPtSlides as PowerPoint.Slide
关于vba - 引用 powerpoint 演示文稿和幻灯片时出现错误 451,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33690421/
我是一名优秀的程序员,十分优秀!