I have some Excel 2010 VBA code running on a Windows 10 Pro computer. The code creates an object for a DLL, and at the end of the program the object is set to nothing. The code runs fine the first time, but if I run it again it crashes on the CreateObject line with the following error message:
Run-time error '-2147467259 (80004005) Automation error Unspecified error
It seems like the DLL object is not being released and that may be why it crashes when trying to create the object on a second run. I found this web page which may be related: https://support.microsoft.com/en-us/help/178510/excel-automation-fails-second-time-code-runs
Below is some sample code, and the line where it crashes is noted. Any idea how to troubleshoot/fix this? Could this problem be related to running Office 2010 on Windows 10? The code worked on my prior Windows 7 computer. By the way, I'm far from an expert in VBA so some of the terminology I'm using may be off.
Sub AddOverlayToPDF()
Dim BasePath As String
Dim InFolder As String
Dim OutFolder As String
Dim FileName As String
Dim PDF, rslt
BasePath = "C:\Users\macke\Desktop\"
InFolder = BasePath & "Comm Charts - No Legend\"
OutFolder = BasePath & "Comm Charts\"
Set PDF = CreateObject("pdf.Meld") ' <-- *** THIS LINE FAILS ON SECOND RUN ***
FileName = Dir(InFolder & "*")
Do While Len(FileName) > 0
Debug.Print FileName
PDF.setRevOverlay
PDF.setRepeat
PDF.setOverlayPages ("9-11")
PDF.setInFile "C:\Users\macke\Desktop\Legend Overlay.pdf"
PDF.setInFile InFolder & FileName
PDF.setOutFile OutFolder & FileName
rslt = PDF.buildPDF
If rslt < 0 And rslt <> -10 Then
MsgBox ("Error " & rslt)
End If
PDF.setReset
FileName = Dir
Loop
Set PDF = Nothing
End Sub
PDF.Closejust beforeSet PDF = Nothing?