Excel VBA Code crashes PPT Presentation and leads to Error 462

Diskutiere Excel VBA Code crashes PPT Presentation and leads to Error 462 im Office Forum im Bereich Microsoft Community Fragen; Hallo, I have a Code, which starts in Excel and opens a PPT, updates the links, renames the PPT and closes it. The problem: Sometimes (not...
  • Excel VBA Code crashes PPT Presentation and leads to Error 462 Beitrag #1
M

MSCom

Neuer Benutzer
Threadstarter
Dabei seit
20.09.2016
Beiträge
1
Hallo,


I have a Code, which starts in Excel and opens a PPT, updates the links, renames the PPT and closes it. The problem: Sometimes (not always) the PPT Presentation crashes and my code stops running, resulting in the following error message: "Error 462 the remote server machine does not exist or is unavailable"


The PPT seems to crash in different parts of the code but mostly at "Set PP = pptApp.Presentations.Open(pptVorlage)". Sometimes the code works fine for 50 loops, sometimes crashes after the first one.

Link to the files: Link

Please help me, it has already cost me days :/

Kind regards and thanks in advance for your help
Michael







Code:


Option Explicit
Public myfilename As String


Sub Saveas_PPT_and_PDF()

Set ws_company = Tabelle2

Dim PP As PowerPoint.Presentation
Dim sh As Variant
Dim company As String
Dim strPOTX As String
Dim strPfad As String
Dim pptVorlage As String
Dim newpath As String
Dim newpathpdf As String
Dim Cell As Range
Dim pptApp As Object

Application.ScreenUpdating = False

pptVorlage = "C:\Users\Michael\Desktop\Test PPT\MSO Tester.pptx"

company = Dropdown.ws_company.Range("C2").Value

Set pptApp = CreateObject("PowerPoint.Application")

Dim drop As Range
Set drop = ws_company.Range(ws_company.Cells(5, 3), ws_company.Cells(Rows.Count, 3).End(xlUp)).SpecialCells(xlCellTypeVisible)

For Each Cell In drop

ws_company.Range("C2").Value = Cell.Value


'Set PP = Nothing
Set PP = pptApp.Presentations.Open(pptVorlage)'often I get the error message here, so it must crash before this part, correct?

newpath = Replace(pptVorlage, "MSO", "" & Cell & "MSO")


'Application.Wait (Now + TimeValue("0:00:05"))
PP.UpdateLinks
PP.SaveAs newpath

newpathpdf = Replace(newpath, "pptx", "pdf")

PP.ExportAsFixedFormat "" & newpathpdf & "", ppFixedFormatTypePDF, ppFixedFormatIntentPrint

'pptApp.Presentations(newpath).Close
PP.Close

Set PP = Nothing
Next

'this part below closes PPT application if there are no other presentation object open. If there is at least 1, it leaves it open

If IsAppRunning("PowerPoint.Application") Then
If pptApp.Windows.Count = 0 Then

pptApp.Quit
End If
End If


Set pptApp = Nothing
Set PP = Nothing

End Sub




Function IsAppRunning(ByVal sAppName) As Boolean
Dim oApp As Object
'On Error Resume Next
Set oApp = GetObject(, sAppName)
If Not oApp Is Nothing Then
Set oApp = Nothing
IsAppRunning = True
Else
IsAppRunning = False
End If
End Function


 
Thema:

Excel VBA Code crashes PPT Presentation and leads to Error 462

Excel VBA Code crashes PPT Presentation and leads to Error 462 - Ähnliche Themen

Outlook VBA - Kategorien in spezifisches Postfach importieren: Hallo zusammen: Ich habe folgende Quelltexte zu diesem Thema gefunden: 1. Liste aller vorhandenen Kategorien im Standardpostfach erzeugen...
Excel VBA Code crashes PPT Presentation and lead to Error 462: Hallo, you guys are my lost hope. Nobody and nothing was able to help me so far, not google, not Stackoverflow, no other experts. I have a Code...
Excel VBA: Liebe Community! Ich habe Office 365. Ich habe eine Excel Vorlage mit VBA Codes. Diese Vorlage hat jetzt 3 Jahre perfekt funktioniert. Vor 1...
Mittels VBA verschiedene CSV's in Ordnern und Unterordner auslesen: Hallo! Hab eine etwas speziellere Frage. Ich bekomm mehrere CSV's welche gleich aufgebaut sind und mittels Semikolon getrennt sind. Jetzt...
Excel 2016 Laufzeitfehler 9: Hallo! Ich hab zwei identische CSV-Dateien die ich einlese und jeweils den erste und letzten Wert einer Spalte ausgebe. Die beiden CSV-Dateien...

Sucheingaben

vba powerpoint crashes when reopening presentation

,

vba error 462 when opening powerpoint presentation

Oben