尝试打开PowerPoint演示文稿时出现Excel VBA错误467 [英] Excel VBA Error 467 when trying to open a PowerPoint presentation

查看:71
本文介绍了尝试打开PowerPoint演示文稿时出现Excel VBA错误467的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码目标:如果PowerPoint已打开且搜索的演示文稿已打开,则对其进行更新.如果演示文稿已关闭,则将其打开.如果PowerPoint关闭,则创建一个新实例.

Objective of the Code: if PowerPoint is open and the searched Presentation is open, then update it. If the presentation is closed, then open it. In case PowerPoint is closed, then create a new instance.

错误:在过去两周内多个用户在多台计算机上运行该错误之后,今天,其中一位用户收到以下错误消息:

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:

运行时错误467:远程服务器计算机不存在或存在不可用

Run-Time Error 467: The Remote Server machine does not exist or is unavailable

在调试模式下突出显示行代码:

Set ppPres = ppProgram.Presentations.Item(i)

模块代码的相关部分:

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"

如果打开了Powerpoint并显示了一些演示文稿,但没有您想要的演示文稿(PowerPointFile),在出现错误的那一行上,您要做什么?(我等于Presentations.count)

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? (i is equal to the Presentations.count)

我认为这是错误的,应该由之前在行上打开的ActivePresentation代替.

I think it is wrong and shall be replaced by the ActivePresentation just opened on the line before.

也许您可以对代码进行一些重组,以使结构/案例处理更加清晰.

Maybe you can restructure the code a little bit to have a clearer structure / case handling.

这篇关于尝试打开PowerPoint演示文稿时出现Excel VBA错误467的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆