Code print kertas continue

Pada Module1 paste code berikut

Option Explicit

Private Type DOCINFO

pDocName As String

pOutputFile As String

pDatatype As String

End Type

Private Declare Function ClosePrinter Lib “winspool.drv” (ByVal _

hPrinter As Long) As Long

Private Declare Function EndDocPrinter Lib “winspool.drv” (ByVal _

hPrinter As Long) As Long

Private Declare Function EndPagePrinter Lib “winspool.drv” (ByVal _

hPrinter As Long) As Long

Private Declare Function OpenPrinter Lib “winspool.drv” Alias _

“OpenPrinterA” (ByVal pPrinterName As String, phPrinter As Long, _

ByVal pDefault As Long) As Long

Private Declare Function StartDocPrinter Lib “winspool.drv” Alias _

“StartDocPrinterA” (ByVal hPrinter As Long, ByVal Level As Long, _

pDocInfo As DOCINFO) As Long

Private Declare Function StartPagePrinter Lib “winspool.drv” (ByVal _

hPrinter As Long) As Long

Declare Function WritePrinter Lib “winspool.drv” (ByVal _

hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _

pcWritten As Long) As Long

Public lhPrinter As Long

Function LoadPrintRedirect() As Boolean

Dim lReturn As Long

Dim lDoc As Long

Dim MyDocInfo As DOCINFO

ClosePrintRedirect

lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)

If lReturn = 0 Then

Exit Function

End If

MyDocInfo.pDocName = “vbBego – Nardhika System”

MyDocInfo.pOutputFile = vbNullString

MyDocInfo.pDatatype = vbNullString

lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)

Call StartPagePrinter(lhPrinter)

LoadPrintRedirect = True

End Function

Sub ClosePrintRedirect()

Dim lReturn As Long

lReturn = EndPagePrinter(lhPrinter)

lReturn = EndDocPrinter(lhPrinter)

lReturn = ClosePrinter(lhPrinter)

End Sub

Sub WriteToPrinter(sWrittenData As String, Optional WithBR As Boolean = False)

Dim lReturn As Long

Dim lpcWritten As Long

sWrittenData = sWrittenData ‘& IIf(WithBR = True, vbCrLf, “”)

lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _

Len(sWrittenData), lpcWritten)

End Sub

—————————-

Pada Form1 Buat 2 tombol (Command1,Command2)

dan TextBox(Text1)

Paste Code Berikut:

Private Sub Command1_Click()

LoadPrintRedirect

WriteToPrinter Replace(Text1.Text, vbCrLf, Chr(13))

ClosePrintRedirect

End Sub

Private Sub Command2_Click()

esc$ = Chr$(27)

boldon$ = esc$ + “(s3B”

boldoff$ = esc$ + “(s0B”

formfeed$ = Chr$(12)

LoadPrintRedirect

WriteToPrinter boldon$ + “This is in bold” + boldoff$ & vbCrLf

ClosePrintRedirect

End Sub

Private Sub Form_Load()

LoadPrintRedirect

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

ClosePrintRedirect

End Sub

Tulis komentar

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s