简体   繁体   English

尝试打开PowerPoint演示文稿时Excel VBA错误467

[英]Excel VBA Error 467 when trying to open a PowerPoint presentation

Objective of the Code : if PowerPoint is open and the searched Presentation is open, then update it. 代码的目标 :如果PowerPoint已打开并且搜索的演示文稿已打开,则对其进行更新。 If the presentation is closed, then open it. 如果演示文稿已关闭,则将其打开。 In case PowerPoint is closed, then create a new instance. 如果PowerPoint关闭,则创建一个新实例。

Error : after multiple users have ran it on on mulitple computers the past 2 weeks, today one of the users get the following error message: 错误 :过去两个星期内,多个用户在多台计算机上运行了该文件,今天,其中一位用户收到以下错误消息:

Run-Time Error 467: The Remote Server machine does not exist or is unavailable 运行时错误467:远程服务器计算机不存在或不可用

Line code highlightned on debug mode : 在调试模式下突出显示的行代码

Set ppPres = ppProgram.Presentations.Item(i)

Relevant section of the Module Code : 模块代码的相关部分

Public Sub UpdatePowerPoint(PowerPointFile)   

Dim ppProgram                           As PowerPoint.Application
Dim ppPres                              As PowerPoint.Presentation
Dim ppFullPath                          As String
Dim ppName                              As String
Dim activeSlide                         As PowerPoint.Slide

Dim cht                                 As Excel.ChartObject
Dim myShape                             As Object
Dim myChart                             As Object
Dim SlideNum, GPLRank                   As Integer
Dim ShapeNum                            As Integer
Dim shapeStageStat                      As Shape

On Error Resume Next
Set ppProgram = GetObject(, "PowerPoint.Application")
On Error GoTo 0

ppFullPath = PowerPointFile
PPT_Export_Success = True

' check if PowerPoint instance is open
If ppProgram Is Nothing Then
    Set ppProgram = New PowerPoint.Application
    i = 1
Else
    If ppProgram.Presentations.count > 0 Then
        ppName = Mid(ppFullPath, InStrRev(ppFullPath, "\") + 1, Len(ppFullPath))
        i = 1
        ppCount = ppProgram.Presentations.count
        Do Until i = ppCount + 1
            If ppProgram.Presentations.Item(i).Name = ppName Then
                Set ppPres = ppProgram.Presentations.Item(i)
                GoTo OnePager_Pres_Found
            Else
                i = i + 1
            End If
        Loop
    End If
End If

ppProgram.Presentations.Open Filename:=PowerPointFile

' *** Getting the ERROR at the line below ***
Set ppPres = ppProgram.Presentations.Item(i)

OnePager_Pres_Found:
ppPres.Windows(1).Activate  ' activate the One-Pager Presentation in case you have several open, and the One_pager is currently not the app "on-focus"

' --- Added Class script to allow PowerPoint ScreenUpdating set to FALSE ---
Dim myClass_PPT                         As Class_PPT

Set myClass_PPT = New Class_PPT
myClass_PPT.ScreenUpdating = False

' loop through all PowerPoint Slides, and copy all Chart objects from Excel
For ProjectCounter = 0 To NumberofProjectShts
    ' copying charts, shapes and other objects

Next ' ProjectCounter = 0 To NumberofProjectShts

AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set ppPres = Nothing
Set ppProgram = Nothing

End Sub

Your code - extract below - looks a bit weird to me: 您的代码-以下摘录-对我来说有点奇怪:

' check if PowerPoint instance is open
If ppProgram Is Nothing Then
    Set ppProgram = New PowerPoint.Application
    i = 1
Else
    If ppProgram.Presentations.count > 0 Then
        ppName = Mid(ppFullPath, InStrRev(ppFullPath, "\") + 1, Len(ppFullPath))
        i = 1
        ppCount = ppProgram.Presentations.count
        Do Until i = ppCount + 1
            If ppProgram.Presentations.Item(i).Name = ppName Then
                Set ppPres = ppProgram.Presentations.Item(i)
                GoTo OnePager_Pres_Found
            Else
                i = i + 1
            End If
        Loop
    End If
End If

ppProgram.Presentations.Open Filename:=PowerPointFile

' *** Getting the ERROR at the line below ***
Set ppPres = ppProgram.Presentations.Item(i)

OnePager_Pres_Found:
ppPres.Windows(1).Activate  ' activate the One-Pager Presentation in case you have several open, and the One_pager is currently not the app "on-focus"

In the case Powerpoint is opened with some presentations but not the one you want (PowerPointFile), on the line which gives you the error, what are you trying to do? 如果打开了Powerpoint并显示了一些演示文稿,但没有打开所需的演示文稿(PowerPointFile),则在出现错误的那一行上,您要做什么? (i is equal to the Presentations.count) (我等于Presentations.count)

I think it is wrong and shall be replaced by the ActivePresentation just opened on the line before. 我认为这是错误的,应该由之前在网上打开的ActivePresentation代替。

Maybe you can restructure the code a little bit to have a clearer structure / case handling. 也许您可以对代码进行一些重组,以使结构/案例处理更加清晰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM