VBA Список принтеров для печати формы.

Узнай цену своей работы

Формулировка задачи:

Печатаю форму таким способом:
UserForm.PrintForm
Подскажите, пожалуйста, как получить список принтеров и указать "программе" нужный (получить его название, если выбирает пользователь) при таком способе печати? Возможно существуют другие способы печати формы с параметрами?
Хотел бы разместить ListBox, в котором пользователь бы указывал нужный принтер без каких либо других настроек как в диалоговых окнах печати Excel. А я, на основании этого значения, посылал бы из кода форму на печать. При загрузки формы, хотелось бы получать, также, значение принтера установленного по умолчанию.
Заранее благодарен.

Решение задачи: «VBA Список принтеров для печати формы.»

textual
Листинг программы
<font color="blue">Option</font> <font color="blue">Explicit</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> GetProfileString Lib <font color="teal">"Kernel32"</font> _
    Alias <font color="teal">"GetProfileStringA"</font> _
    (<font color="blue">ByVal</font> lpAppName <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpKeyName <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpDefault <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpReturnedString <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> nSize <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">Long</font>
    
<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> WriteProfileString Lib <font color="teal">"Kernel32"</font> _
    Alias <font color="teal">"WriteProfileStringA"</font> _
    (<font color="blue">ByVal</font> lpszSection <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpszKeyName <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpszString <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> SendMessage Lib <font color="teal">"user32"</font> _
    Alias <font color="teal">"SendMessageA"</font> _
    (<font color="blue">ByVal</font> hwnd <font color="blue">As</font> <font color="blue">Long</font>, _
    <font color="blue">ByVal</font> wMsg <font color="blue">As</font> <font color="blue">Long</font>, _
    <font color="blue">ByVal</font> wParam <font color="blue">As</font> <font color="blue">Long</font>, _
    lparam <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Const</font> HWND_BROADCAST = &HFFFF
                                                                                
<font color="blue">Private</font> <font color="blue">Const</font> WM_WININICHANGE = &H1A

<font color="blue">Private</font> <font color="blue">Type</font> OSVERSIONINFO
    dwOSVersionInfoSize <font color="blue">As</font> <font color="blue">Long</font>
    dwMajorVersion <font color="blue">As</font> <font color="blue">Long</font>
    dwMinorVersion <font color="blue">As</font> <font color="blue">Long</font>
    dwBuildNumber <font color="blue">As</font> <font color="blue">Long</font>
    dwPlatformId <font color="blue">As</font> <font color="blue">Long</font>
    szCSDVersion <font color="blue">As</font> <font color="blue">String</font> * <font color="darkblue"><b>128</b></font>
<font color="blue">End</font> <font color="blue">Type</font>


<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> GetVersionExA Lib <font color="teal">"Kernel32"</font> _
    (lpVersionInformation <font color="blue">As</font> OSVERSIONINFO) <font color="blue">As</font> <font color="blue">Integer</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> OpenPrinter Lib <font color="teal">"winspool.drv"</font> _
    Alias <font color="teal">"OpenPrinterA"</font> _
    (<font color="blue">ByVal</font> pPrinterName <font color="blue">As</font> <font color="blue">String</font>, _
    phPrinter <font color="blue">As</font> <font color="blue">Long</font>, _
    pDefault <font color="blue">As</font> PRINTER_DEFAULTS) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> SetPrinter Lib <font color="teal">"winspool.drv"</font> _
    Alias <font color="teal">"SetPrinterA"</font> _
    (<font color="blue">ByVal</font> hPrinter <font color="blue">As</font> <font color="blue">Long</font>, _
    <font color="blue">ByVal</font> Level <font color="blue">As</font> <font color="blue">Long</font>, _
    pPrinter <font color="blue">As</font> Any, _
    <font color="blue">ByVal</font> Command <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> GetPrinter Lib <font color="teal">"winspool.drv"</font> _
    Alias <font color="teal">"GetPrinterA"</font> _
    (<font color="blue">ByVal</font> hPrinter <font color="blue">As</font> <font color="blue">Long</font>, _
    <font color="blue">ByVal</font> Level <font color="blue">As</font> <font color="blue">Long</font>, _
    pPrinter <font color="blue">As</font> Any, _
    <font color="blue">ByVal</font> cbBuf <font color="blue">As</font> <font color="blue">Long</font>, _
    pcbNeeded <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> lstrcpy Lib <font color="teal">"Kernel32"</font> _
    Alias <font color="teal">"lstrcpyA"</font> _
    (<font color="blue">ByVal</font> lpString1 <font color="blue">As</font> <font color="blue">String</font>, _
    <font color="blue">ByVal</font> lpString2 <font color="blue">As</font> Any) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> ClosePrinter Lib <font color="teal">"winspool.drv"</font> _
    (<font color="blue">ByVal</font> hPrinter <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Declare</font> <font color="blue">Function</font> GetLastError Lib <font color="teal">"Kernel32"</font> () <font color="blue">As</font> <font color="blue">Long</font>

<font color="blue">Private</font> <font color="blue">Const</font> CCHDEVICENAME = <font color="darkblue"><b>32</b></font>
<font color="blue">Private</font> <font color="blue">Const</font> CCHFORMNAME = <font color="darkblue"><b>32</b></font>

<font color="blue">Private</font> <font color="blue">Const</font> STANDARD_RIGHTS_REQUIRED = &HF0000
<font color="blue">Private</font> <font color="blue">Const</font> PRINTER_ACCESS_ADMINISTER = &H4
<font color="blue">Private</font> <font color="blue">Const</font> PRINTER_ACCESS_USE = &H8
<font color="blue">Private</font> <font color="blue">Const</font> PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED <font color="blue">Or</font> PRINTER_ACCESS_ADMINISTER <font color="blue">Or</font> PRINTER_ACCESS_USE)

<font color="blue">Private</font> <font color="blue">Const</font> PRINTER_ATTRIBUTE_DEFAULT = <font color="darkblue"><b>4</b></font>

<font color="blue">Private</font> <font color="blue">Type</font> DEVMODE
    dmDeviceName <font color="blue">As</font> <font color="blue">String</font> * CCHDEVICENAME
    dmSpecVersion <font color="blue">As</font> <font color="blue">Integer</font>
    dmDriverVersion <font color="blue">As</font> <font color="blue">Integer</font>
    dmSize <font color="blue">As</font> <font color="blue">Integer</font>
    dmDriverExtra <font color="blue">As</font> <font color="blue">Integer</font>
    dmFields <font color="blue">As</font> <font color="blue">Long</font>
    dmOrientation <font color="blue">As</font> <font color="blue">Integer</font>
    dmPaperSize <font color="blue">As</font> <font color="blue">Integer</font>
    dmPaperLength <font color="blue">As</font> <font color="blue">Integer</font>
    dmPaperWidth <font color="blue">As</font> <font color="blue">Integer</font>
    dmScale <font color="blue">As</font> <font color="blue">Integer</font>
    dmCopies <font color="blue">As</font> <font color="blue">Integer</font>
    dmDefaultSource <font color="blue">As</font> <font color="blue">Integer</font>
    dmPrintQuality <font color="blue">As</font> <font color="blue">Integer</font>
    dmColor <font color="blue">As</font> <font color="blue">Integer</font>
    dmDuplex <font color="blue">As</font> <font color="blue">Integer</font>
    dmYResolution <font color="blue">As</font> <font color="blue">Integer</font>
    dmTTOption <font color="blue">As</font> <font color="blue">Integer</font>
    dmCollate <font color="blue">As</font> <font color="blue">Integer</font>
    dmFormName <font color="blue">As</font> <font color="blue">String</font> * CCHFORMNAME
    dmLogPixels <font color="blue">As</font> <font color="blue">Integer</font>
    dmBitsPerPel <font color="blue">As</font> <font color="blue">Long</font>
    dmPelsWidth <font color="blue">As</font> <font color="blue">Long</font>
    dmPelsHeight <font color="blue">As</font> <font color="blue">Long</font>
    dmDisplayFlags <font color="blue">As</font> <font color="blue">Long</font>
    dmDisplayFrequency <font color="blue">As</font> <font color="blue">Long</font>
    dmICMMethod <font color="blue">As</font> <font color="blue">Long</font>
    dmICMIntent <font color="blue">As</font> <font color="blue">Long</font>
    dmMediaType <font color="blue">As</font> <font color="blue">Long</font>
    dmDitherType <font color="blue">As</font> <font color="blue">Long</font>
    dmReserved1 <font color="blue">As</font> <font color="blue">Long</font>
    dmReserved2 <font color="blue">As</font> <font color="blue">Long</font>
<font color="blue">End</font> <font color="blue">Type</font>

<font color="blue">Private</font> <font color="blue">Type</font> PRINTER_INFO_5
    pPrinterName <font color="blue">As</font> <font color="blue">String</font>
    pPortName <font color="blue">As</font> <font color="blue">String</font>
    Attributes <font color="blue">As</font> <font color="blue">Long</font>
    DeviceNotSelectedTimeout <font color="blue">As</font> <font color="blue">Long</font>
    TransmissionRetryTimeout <font color="blue">As</font> <font color="blue">Long</font>
<font color="blue">End</font> <font color="blue">Type</font>

<font color="blue">Private</font> <font color="blue">Type</font> PRINTER_DEFAULTS
    pDatatype <font color="blue">As</font> <font color="blue">Long</font>
    pDevmode <font color="blue">As</font> DEVMODE
    DesiredAccess <font color="blue">As</font> <font color="blue">Long</font>
<font color="blue">End</font> <font color="blue">Type</font>

<font color="blue">Private</font> m_sCurrPrinterDevName <font color="blue">As</font> <font color="blue">String</font>
<font color="blue">Private</font> m_sPrevPrinterDevName <font color="blue">As</font> <font color="blue">String</font>
<font color="blue">Private</font> m_sPrevPrinterDriver <font color="blue">As</font> <font color="blue">String</font>
<font color="blue">Private</font> m_sPrevPrinterPort <font color="blue">As</font> <font color="blue">String</font>

<font color="blue">Private</font> <font color="blue">Function</font> PtrCtoVbString(Add <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">String</font>
    <font color="00AA00">'Source - Article ID: Q78304</font>
    <font color="blue">Dim</font> sTemp <font color="blue">As</font> <font color="blue">String</font> * <font color="darkblue"><b>512</b></font>, x <font color="blue">As</font> <font color="blue">Long</font>
    
    x = lstrcpy(sTemp, Add)
    <font color="blue">If</font> (InStr(<font color="darkblue"><b>1</b></font>, sTemp, Chr(<font color="darkblue"><b>0</b></font>)) = <font color="darkblue"><b>0</b></font>) <font color="blue">Then</font>
         PtrCtoVbString = <font color="teal">""</font>
    <font color="blue">Else</font>
         PtrCtoVbString = Left(sTemp, InStr(<font color="darkblue"><b>1</b></font>, sTemp, Chr(<font color="darkblue"><b>0</b></font>)) - <font color="darkblue"><b>1</b></font>)
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">End</font> <font color="blue">Function</font>

<font color="blue">Private</font> <font color="blue">Function</font> SetDefaultPrinter(<font color="blue">ByVal</font> DeviceName <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">ByVal</font> DriverName <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">ByVal</font> PrinterPort <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Boolean</font>
    <font color="blue">Dim</font> DeviceLine <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> r <font color="blue">As</font> <font color="blue">Long</font>
    <font color="blue">Dim</font> l <font color="blue">As</font> <font color="blue">Long</font>
    
    DeviceLine = DeviceName & <font color="teal">","</font> & DriverName & <font color="teal">","</font> & PrinterPort

    r = WriteProfileString(<font color="teal">"windows"</font>, <font color="teal">"Device"</font>, DeviceLine)
    
    <font color="blue">If</font> r <font color="blue">Then</font>

        l = SendMessage(HWND_BROADCAST, WM_WININICHANGE, <font color="darkblue"><b>0</b></font>, <font color="teal">"windows"</font>)
        SetDefaultPrinter = True
        m_sCurrPrinterDevName = DeviceName
    <font color="blue">Else</font>
        SetDefaultPrinter = False
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">End</font> <font color="blue">Function</font>

<font color="blue">Private</font> <font color="blue">Function</font> Win95SetDefaultPrinter(<font color="blue">ByRef</font> DeviceName <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Boolean</font>
    <font color="blue">Dim</font> Handle <font color="blue">As</font> <font color="blue">Long</font>
    <font color="blue">Dim</font> pd <font color="blue">As</font> PRINTER_DEFAULTS
    <font color="blue">Dim</font> x <font color="blue">As</font> <font color="blue">Long</font>
    <font color="blue">Dim</font> need <font color="blue">As</font> <font color="blue">Long</font>
    <font color="blue">Dim</font> pi5 <font color="blue">As</font> PRINTER_INFO_5
    <font color="blue">Dim</font> LastError <font color="blue">As</font> <font color="blue">Long</font>


    <font color="blue">If</font> DeviceName = <font color="teal">""</font> <font color="blue">Then</font>
        Win95SetDefaultPrinter = False
        <font color="blue">Exit</font> <font color="blue">Function</font>
    <font color="blue">End</font> <font color="blue">If</font>


    pd.pDatatype = <font color="darkblue"><b>0</b></font>&
    pd.DesiredAccess = PRINTER_ALL_ACCESS


    x = OpenPrinter(DeviceName, Handle, pd)

    <font color="blue">If</font> x = False <font color="blue">Then</font>
        Win95SetDefaultPrinter = False
        <font color="blue">Exit</font> <font color="blue">Function</font>
    <font color="blue">End</font> <font color="blue">If</font>

    x = GetPrinter(Handle, <font color="darkblue"><b>5</b></font>, <font color="blue">ByVal</font> <font color="darkblue"><b>0</b></font>&, <font color="darkblue"><b>0</b></font>, need)

    <font color="blue">ReDim</font> t((need \ <font color="darkblue"><b>4</b></font>)) <font color="blue">As</font> <font color="blue">Long</font>

    x = GetPrinter(Handle, <font color="darkblue"><b>5</b></font>, t(<font color="darkblue"><b>0</b></font>), need, need)

    <font color="blue">If</font> x = False <font color="blue">Then</font>
        Win95SetDefaultPrinter = False
        <font color="blue">Exit</font> <font color="blue">Function</font>
    <font color="blue">End</font> <font color="blue">If</font>

    pi5.pPrinterName = PtrCtoVbString(t(<font color="darkblue"><b>0</b></font>))
    pi5.pPortName = PtrCtoVbString(t(<font color="darkblue"><b>1</b></font>))
    pi5.Attributes = t(<font color="darkblue"><b>2</b></font>)
    pi5.DeviceNotSelectedTimeout = t(<font color="darkblue"><b>3</b></font>)
    pi5.TransmissionRetryTimeout = t(<font color="darkblue"><b>4</b></font>)


    pi5.Attributes = PRINTER_ATTRIBUTE_DEFAULT


    x = SetPrinter(Handle, <font color="darkblue"><b>5</b></font>, pi5, <font color="darkblue"><b>0</b></font>)
    
    <font color="blue">If</font> x = False <font color="blue">Then</font>
        Win95SetDefaultPrinter = False
        <font color="blue">Exit</font> <font color="blue">Function</font>
    <font color="blue">End</font> <font color="blue">If</font>

    <font color="blue">Call</font> ClosePrinter(Handle)
    m_sCurrPrinterDevName = DeviceName
    Win95SetDefaultPrinter = True
<font color="blue">End</font> <font color="blue">Function</font>

<font color="blue">Private</font> <font color="blue">Sub</font> GetDriverAndPort(<font color="blue">ByVal</font> Buffer <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">ByRef</font> DriverName <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">ByRef</font> PrinterPort <font color="blue">As</font> <font color="blue">String</font>)
    <font color="blue">Dim</font> iDriver <font color="blue">As</font> <font color="blue">Integer</font>
    <font color="blue">Dim</font> iPort <font color="blue">As</font> <font color="blue">Integer</font>
    
    DriverName = <font color="teal">""</font>
    PrinterPort = <font color="teal">""</font>

    iDriver = InStr(Buffer, <font color="teal">","</font>)
    <font color="blue">If</font> iDriver > <font color="darkblue"><b>0</b></font> <font color="blue">Then</font>

        DriverName = Left(Buffer, iDriver - <font color="darkblue"><b>1</b></font>)

        iPort = InStr(iDriver + <font color="darkblue"><b>1</b></font>, Buffer, <font color="teal">","</font>)

        <font color="blue">If</font> iPort > <font color="darkblue"><b>0</b></font> <font color="blue">Then</font>

            PrinterPort = <font color="blue">Mid</font>(Buffer, iDriver + <font color="darkblue"><b>1</b></font>, iPort - iDriver - <font color="darkblue"><b>1</b></font>)
        <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">End</font> <font color="blue">Sub</font>

<font color="blue">Private</font> <font color="blue">Function</font> WinNTSetDefaultPrinter(<font color="blue">ByRef</font> DeviceName <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Boolean</font>
    <font color="blue">Dim</font> Buffer <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> DriverName <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> PrinterPort <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> r <font color="blue">As</font> <font color="blue">Long</font>
    
    <font color="blue">If</font> DeviceName <> <font color="teal">""</font> <font color="blue">Then</font>

        Buffer = Space(<font color="darkblue"><b>1024</b></font>)
        r = GetProfileString(<font color="teal">"PrinterPorts"</font>, DeviceName, <font color="teal">""</font>, Buffer, Len(Buffer))
        

        <font color="blue">Call</font> GetDriverAndPort(Buffer, DriverName, PrinterPort)

        <font color="blue">If</font> DriverName <> <font color="teal">""</font> <font color="blue">And</font> PrinterPort <> <font color="teal">""</font> <font color="blue">Then</font>
            WinNTSetDefaultPrinter = SetDefaultPrinter(DeviceName, DriverName, PrinterPort)
        <font color="blue">Else</font>
            WinNTSetDefaultPrinter = False
        <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">End</font> <font color="blue">Function</font>

<font color="blue">Function</font> SetPrinterAsDefault(<font color="blue">ByVal</font> DeviceName <font color="blue">As</font> <font color="blue">String</font>) <font color="blue">As</font> <font color="blue">Boolean</font>
    <font color="blue">Dim</font> osinfo <font color="blue">As</font> OSVERSIONINFO
    <font color="blue">Dim</font> retvalue <font color="blue">As</font> <font color="blue">Integer</font>

    osinfo.dwOSVersionInfoSize = <font color="darkblue"><b>148</b></font>
    osinfo.szCSDVersion = Space$(<font color="darkblue"><b>128</b></font>)
    retvalue = GetVersionExA(osinfo)
    

    <font color="blue">If</font> m_sCurrPrinterDevName <> DeviceName <font color="blue">Then</font>

        <font color="blue">If</font> osinfo.dwMajorVersion = <font color="darkblue"><b>3</b></font> <font color="blue">And</font> osinfo.dwMinorVersion = <font color="darkblue"><b>51</b></font> <font color="blue">And</font> osinfo.dwBuildNumber = <font color="darkblue"><b>1057</b></font> <font color="blue">And</font> osinfo.dwPlatformId = <font color="darkblue"><b>2</b></font> <font color="blue">Then</font>
            SetPrinterAsDefault = WinNTSetDefaultPrinter(DeviceName)

        <font color="blue">ElseIf</font> osinfo.dwMajorVersion = <font color="darkblue"><b>4</b></font> <font color="blue">And</font> osinfo.dwPlatformId = <font color="darkblue"><b>1</b></font> <font color="blue">Then</font>
            SetPrinterAsDefault = Win95SetDefaultPrinter(DeviceName)

        <font color="blue">ElseIf</font> osinfo.dwMajorVersion = <font color="darkblue"><b>4</b></font> <font color="blue">And</font> osinfo.dwMinorVersion = <font color="darkblue"><b>0</b></font> <font color="blue">And</font> osinfo.dwBuildNumber = <font color="darkblue"><b>1381</b></font> <font color="blue">And</font> osinfo.dwPlatformId = <font color="darkblue"><b>2</b></font> <font color="blue">Then</font>
            SetPrinterAsDefault = WinNTSetDefaultPrinter(DeviceName)
            
        <font color="blue">ElseIf</font> osinfo.dwMajorVersion > <font color="darkblue"><b>4</b></font> <font color="blue">Then</font>
            SetPrinterAsDefault = WinNTSetDefaultPrinter(DeviceName)
        <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">Else</font>
        SetPrinterAsDefault = True
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">End</font> <font color="blue">Function</font>

<font color="blue">Private</font> <font color="blue">Sub</font> Class_Initialize()
    <font color="blue">Dim</font> Buffer <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> r <font color="blue">As</font> <font color="blue">Long</font>
    
    Buffer = Space(<font color="darkblue"><b>8192</b></font>)
    r = GetProfileString(<font color="teal">"windows"</font>, <font color="teal">"Device"</font>, <font color="teal">""</font>, Buffer, Len(Buffer))
    <font color="blue">If</font> r <font color="blue">Then</font>
        
        Buffer = <font color="blue">Mid</font>(Buffer, <font color="darkblue"><b>1</b></font>, r)
        
        m_sPrevPrinterDevName = <font color="blue">Mid</font>(Buffer, <font color="darkblue"><b>1</b></font>, InStr(Buffer, <font color="teal">","</font>) - <font color="darkblue"><b>1</b></font>)
        m_sPrevPrinterDriver = <font color="blue">Mid</font>(Buffer, InStr(Buffer, <font color="teal">","</font>) + <font color="darkblue"><b>1</b></font>, InStrRev(Buffer, <font color="teal">","</font>) - InStr(Buffer, <font color="teal">","</font>) - <font color="darkblue"><b>1</b></font>)
        m_sPrevPrinterPort = <font color="blue">Mid</font>(Buffer, InStrRev(Buffer, <font color="teal">","</font>) + <font color="darkblue"><b>1</b></font>)
    <font color="blue">Else</font>
        m_sPrevPrinterDevName = <font color="teal">""</font>
        m_sPrevPrinterDriver = <font color="teal">""</font>
        m_sPrevPrinterDevName = <font color="teal">""</font>
    <font color="blue">End</font> <font color="blue">If</font>
    m_sCurrPrinterDevName = m_sPrevPrinterDevName
<font color="blue">End</font> <font color="blue">Sub</font>

<font color="blue">Private</font> <font color="blue">Sub</font> Class_Terminate()

    <font color="blue">Call</font> SetPrinterAsDefault(m_sPrevPrinterDevName)
<font color="blue">End</font> <font color="blue">Sub</font>

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 4 из 5
Похожие ответы