#If Win32 Then Public Type DOC_INFO_1 pDocName As String pOutputFile As String pDatatype As String End Type #End If #If Win32 Then Public Declare Function OpenPrinter& Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) ' Third param changed to long Public Declare Function StartDocPrinter& Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1) Public Declare Function StartPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long) Public Declare Function WritePrinter& Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) Public Declare Function EndDocPrinter& Lib "winspool.drv" (ByVal hPrinter As Long) Public Declare Function EndPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long) Public Declare Function ClosePrinter& Lib "winspool.drv" (ByVal hPrinter As Long) #End If Public Function ToPrinter(ByVal PrnData As String, ByVal PrinterDeviceName As String) Dim hPrinter& Dim jobid& Dim res& Dim written& Dim printdata$ Dim docinfo As DOC_INFO_1 res& = OpenPrinter(PrinterDeviceName, hPrinter, 0) If res = 0 Then MsgBox "Unable to open the printer" Exit Function End If docinfo.pDocName = "MyDoc" docinfo.pOutputFile = vbNullString docinfo.pDatatype = vbNullString jobid = StartDocPrinter(hPrinter, 1, docinfo) Call StartPagePrinter(hPrinter) printdata$ = PrnData & vbLineFeed Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$), written) Call EndPagePrinter(hPrinter) Call EndDocPrinter(hPrinter) Call ClosePrinter(hPrinter) ' Close when done End Function