Откройте Powerpoint и запустите этот код в первый раз, каждый был в порядке
но запустил его во второй раз, система выкинула runtime error 91
и выделила oPres.Close
Я полностью выключил powerpoint и снова запустил его, первый раунд в порядке, но во втором раунде произошла ошибка.
Я немного запутался.
Sub PrintAll()
Dim CurrentFolder As String
Dim FileName As String
Dim myPath As String
Dim myPath2 As String
Dim UniqueName As Boolean
Dim PDFName As String
Dim strCurrentFile As String
Dim strFileSpec As String
Dim sldTemp As Slide
Dim lngTemp As Long
Dim lngCount As Long
Dim PP As Object
Dim oPres As Object
CurrentFolder = ActivePresentation.Path & "\" 'get current folder
strFileSpec = "*.ppt"
strCurrentFile = Dir$(CurrentFolder & strFileSpec)
FileName = Mid(strCurrentFile, InStrRev(strCurrentFile, "\") + 1, _
InStrRev(strCurrentFile, ".") - InStrRev(strCurrentFile, "\") - 1)
Debug.Print "FileName: " + FileName
PDFName = CurrentFolder & FileName & ".pdf"
Debug.Print "PDFName: " + PDFName
Set PP = CreateObject("Powerpoint.Application") ' Late binding
'-----------------------------------------Start Loop-----------------------------------------
While strCurrentFile <> ""
On Error Resume Next
Set oPres = PP.Presentations.Open(CurrentFolder & strCurrentFile)
Debug.Print "CurrentFolder: " + strCurrentFile
If Err.Number <> 0 Then
Debug.Print "Unable to open " & FileName
End If
FileName = Mid(strCurrentFile, InStrRev(strCurrentFile, "\") + 1, _
InStrRev(strCurrentFile, ".") - InStrRev(strCurrentFile, "\") - 1)
Debug.Print "FileName: " + FileName
PDFName = CurrentFolder & FileName & ".pdf"
Debug.Print "PDFName: " + PDFName
On Error GoTo 0
oPres.Close 'The 91 error occurred here
strCurrentFile = Dir()
Wend
'-----------------------------------------End Loop-----------------------------------------
PP.Quit
Set PP = Nothing
End Sub