V8i PowerDraft SS4 VBA - Calling Print Organizer, opening PSETs error handling?

Hi Guys,

I'm using Excel VBA to call Microstation and then from a list of directories open .pset files (previously created manually) contained within each directory. The intention is to open each pset, print to PDF and move onto the next PSET until all in the list are completed.

I have gotten the code to do exactly what I want, however the issue comes when the printorganizer attempts to print a PSET which references corrupt files/folders (in other words it hasn't been setup properly) . From what I can tell this causes a complete failure and the program hangs indefinitely, the message 'waiting for OLE automation etc.' comes up, in the end the excel application has to be closed through the task manager.

What form of error handling will manage this? Print organizer is called using key-in as I don't believe there are objects I can access and therefore I am unable to predict the error state.

Code below:

Sub RunPSets()

Dim myDGN As New MicroStationDGN.Application
Dim nFile As DesignFile

Dim i As Integer
Dim ws_FH As Worksheet
Dim rngPSETs As Range
Dim openPSETDIR As String
Dim outputDir As String
Dim userWarningList As String
Dim answer As Integer

Set ws_FH = Application.Worksheets("Fill History")
Set rngPSETs = ws_FH.Range("M12:O100")

Dim j As Integer

outputDir = Main_Form.lblOutputDir.Caption

If outputDir <> "" Then

    For j = 1 To rngPSETs.Rows.Count
    
        If rngPSETs.Cells(j, 1) <> "" Then
        userWarningList = userWarningList & rngPSETs.Cells(j, 1) & " " & rngPSETs.Cells(j, 2) & vbNewLine
        End If
        
    Next j
    
Else
    
        MsgBox "Select output directory first!"
        
        Exit Sub
   
End If

answer = MsgBox("Print to PDF the following Isolations to:" & vbNewLine & outputDir & vbNewLine & vbNewLine & userWarningList, vbYesNo, "Print Isolations")

If answer = vbYes Then

    Const PrintDriver As String = "MTM-PDF-Plotdrv.plt"
    'Const PrintDriver As String = "pdf.pltcfg"
    'myDGN.CadInputQueue.SendCommand "printorganizer exit"
    
            Set nFile = myDGN.OpenDesignFile("J:\Engineering Division\15 Design Production\Signalling\Isolations\- Source Files\Isolation Template.dgn", True)
            Main_Form.lblStatus.ForeColor = &H40C0&
            myDGN.CadInputQueue.SendKeyin "mdl load bentley.microstation.printorganizer.dll"
            'myDGN.CadInputQueue.SendCommand "printorganizer new"
            Debug.Print "PRINTING STARTED"
            
            
            For i = 1 To rngPSETs.Rows.Count
                If rngPSETs.Cells(i, 1) <> "" Then
                openPSETDIR = rngPSETs.Cells(i, 3)
                Main_Form.lblStatus.Caption = "Printing....TBA: " & rngPSETs(i, 1) & " " & rngPSETs.Cells(i, 2)
                myDGN.CadInputQueue.SendKeyin "printorganizer open " & openPSETDIR
                Debug.Print "PSET OPENED: " & openPSETDIR
                myDGN.CadInputQueue.SendKeyin "printorganizer printerdriver " & PrintDriver
                myDGN.CadInputQueue.SendKeyin "printorganizer printdestination " & outputDir & "\" & rngPSETs.Cells(i, 1) & " " & rngPSETs.Cells(i, 2) & ".pdf"
                myDGN.CadInputQueue.SendKeyin "printorganizer print all"
                Debug.Print "Printed PSET: " & rngPSETs(i, 1)
                Main_Form.lblStatus.Caption = "TBA: " & rngPSETs(i, 1) & " " & rngPSETs.Cells(i, 2) & " printed."
                End If
                
            Next i

        nFile.Close
        Debug.Print "Printing FINISHED"
        
        Set myDGN = Nothing
        myDGN.Quit
        
        MsgBox "Printing has finished!"


Else

Exit Sub

End If

End Sub

Does anyone have any ideas how I can safe proof this automation from errors of this type?

Thanks


Regards

Boris