V8i - VBA code for Printing from Excel

Hello all,

I am starting with VB for microstation and I would like to create a VBA macro in EXCEL that would allow me to print a selection of Microstation files to PDF files(based in a column).

For the looping process in Excel and opening the Microstation files from Excel, I do not have a problem but for the Print, aie aie!

Therefore, I used the Record facilities in VBA Project Manager and the result is below (Macro1). It is working fine but the only anoing thing is that it open 2 dialog Boxes:

      1 for the "select Printer Driver Configuration File" and 1 for the "Save Print As".

How could I avoid opening these 2 dialog Boxes and forcing the selection of a Printer Conf File and save as

 

Hello all,

I am starting with VB for microstation and I would like to create a VBA macro in EXCEL that would allow me to print a selection of Microstation files (based in a column).

For the looping process in Excel and opening the Microstation files from Excel, I do not have a problem but for the Print, aie aie!

Therefore, I used the Record facilities in VBA Project Manager and the result is below (Macro1). It is working fine but the only boring thing is that it open 2 dialog Boxes and this for all files!

      1 for the "select Printer Driver Configuration File" and 1 for the "Save Print As".

Does anyone could help me on this? Thanks in adcance

Herve

Sub Macro1()
    Dim startPoint As Point3d
    Dim point As Point3d, point2 As Point3d
    Dim lngTemp As Long
'   Start a command
    CadInputQueue.SendCommand "FIT VIEW EXTENDED 1"
    CadInputQueue.SendCommand "DIALOG PLOT"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT DRIVER"
    Dim modalHandler As New Macro1ModalHandler
    AddModalDialogEventsHandler modalHandler
'   The following statement opens modal dialog "Select Printer Driver Configuration File"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
'   Set a variable associated with a dialog box
    SetCExpressionValue "plotUI.uiPaperName", "ISO A3", "PLOTDLG"
    SetCExpressionValue "plotUI.uiPaperName", "ISO A3", "PLOTDLG"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT BOUNDARY FIT ALL"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
'   The following statement opens modal dialog "Save Print As"
    CadInputQueue.SendCommand "PRINT EXECUTE"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT EXIT PLOTDLG"
    CadInputQueue.SendCommand "MDL UNLOAD PLOTDLG"
    RemoveModalDialogEventsHandler modalHandler
    CommandState.StartDefaultCommand
End Sub

Implements IModalDialogEvents
Private Sub IModalDialogEvents_OnDialogClosed(ByVal DialogBoxName As String, ByVal DialogResult As MsdDialogBoxResult)
End SubPrivate Sub IModalDialogEvents_OnDialogOpened(ByVal DialogBoxName As String, DialogResult As MsdDialogBoxResult)
    If DialogBoxName = "Select Printer Driver Configuration File" Then
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setDirectoryCmd C:\Documents and Settings\All Users\Application Data\Bentley\MicroStation V8i (SELECTseries 1)\WorkSpace\System\pltcfg\"
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setFileNameCmd Herve_Mono_pdf.pltcfg"
    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK
    End If  ' Select Printer Driver Configuration File
    If DialogBoxName = "Save Print As" Then
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setDirectoryCmd C:\Documents and Settings\All Users\Application Data\Bentley\MicroStation V8i (SELECTseries 1)\WorkSpace\Projects\Untitled\out\"
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setFileNameCmd T1201.pdf"
    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK
    End If  ' Save Print As
End Sub