- ' Mettez un Common Dialog nommé "MonDialog"
- ' Mettez un RichTextBox nommé "MonRTF"
- ' Et appelez la fonction comme ceci pour imprimer le contenu du RichTextBox :
- '
- ' Ret = ImprimeRTF(MonDialog, MonRTF)
- '
-
- Function ImprimeRTF(LeDialog As CommonDialog, LeRtf As RichTextBox) As Boolean
- On Local Error GoTo Error_Handler:
-
- With LeDialog
- .CancelError = True
- .Flags = cdlPDReturnDC + cdlPDNoPageNums
-
- If LeRtf .SelLength = 0 Then
- .Flags = .Flags + cdlPDAllPages
- Else
- .Flags = .Flags + cdlPDSelection
- End If
- .ShowPrinter
-
- Printer.Print ""
- LeDialog.SelPrint .hdc
- Printer.EndDoc
- ImprimeRTF = True
- End With
-
- Exit Function
-
- Error_Handler:
- If Err <> cdlCancel Then
- ImprimeRTF = False
- MsgBox "Erreur " & Err & "; " & Error
- End If
- End Function
-
' Mettez un Common Dialog nommé "MonDialog"
' Mettez un RichTextBox nommé "MonRTF"
' Et appelez la fonction comme ceci pour imprimer le contenu du RichTextBox :
'
' Ret = ImprimeRTF(MonDialog, MonRTF)
'
Function ImprimeRTF(LeDialog As CommonDialog, LeRtf As RichTextBox) As Boolean
On Local Error GoTo Error_Handler:
With LeDialog
.CancelError = True
.Flags = cdlPDReturnDC + cdlPDNoPageNums
If LeRtf .SelLength = 0 Then
.Flags = .Flags + cdlPDAllPages
Else
.Flags = .Flags + cdlPDSelection
End If
.ShowPrinter
Printer.Print ""
LeDialog.SelPrint .hdc
Printer.EndDoc
ImprimeRTF = True
End With
Exit Function
Error_Handler:
If Err <> cdlCancel Then
ImprimeRTF = False
MsgBox "Erreur " & Err & "; " & Error
End If
End Function