Hello Excel experts!
I am working on a PowerPoint file lister, but some of these pptx files are bad. They cannot be opened, and therefore cause errors in my code. I cannot seem to find a method to say "I this line errors, just skip further down to here". All error handling solution I can see are general for the Sub and is not specialised for errors in a single line. I am looking for the VBA equivalent of IFERROR().
The line in my code that sometimes errors is:
Set myPresentation = PowerPointApp.Presentations.Open(oFile, ReadOnly:=msoTrue, WithWindow:=msoFalse) 'Problem is here
I have checked the files when it happens, and these files cannot be opened. My code is otherwise working well.
Here is my full Sub for reference:
Sub Files_with_Unicode_Chars()
Dim FileSysObj As Object 'Scripting.FileSystemObject
Dim oFolder As Object 'Scripting.Folder
Dim oFile As Object
Dim vCurrDir As String, vCrit As String
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim Slidecount As Long
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set PowerPointApp = CreateObject("PowerPoint.Application")
vCurrDir = "C:\Users\b017646\Downloads\Alle ppt filer"
vCrit = ".pptx"
Set oFolder = FileSysObj.GetFolder(vCurrDir)
For Each oFile In oFolder.Files
With oFile
Select Case Mid(.Name, InStrRev(.Name, "."))
Case vCrit
Set myPresentation = PowerPointApp.Presentations.Open(oFile, ReadOnly:=msoTrue, WithWindow:=msoFalse) 'Problem is here
Rem If file is bad, it causes and error. Would like to get around this somehow
'Ark1.Cells(Row, 1).Value = oFile
'Ark1.Cells(Row, 2).Value = myPresentation.Slides.Count
'Ark1.Cells(Row, 3).Value = oFile.DateLastModified
Debug.Print oFile; myPresentation.Slides.Count; oFile.DateLastModified
End Select: End With: Next
End Sub
I hope You can help
GregersDK
Bookmarks