I'm testing to see if a network file exists.
I find that with some files the VBA process stops and opens the debug window without any error, just highlighting a line (which I indicate below). If I press F5 to continue, the process finishes without any problem.
FilePath = "\\network\file.pdf"
If Not Dir(FilePath, vbDirectory) = vbNullString Then
' The process gets stuck on the next line
' I need to add a delay to prevent it to stop like: Application.Wait Now + #12:00:05 AM#
Worksheets(valRef).OLEObjects.Add Filename:=FilePath, Link:=False, DisplayAsIcon:=False
Else
' Do something else
End If
It seems to happen when files are very big. If I add a wait, then the process is okay, but I'm delaying the whole process significantly when I have to process many files. Is there a way to prevent it from stopping?