UNKNOWN '************************************** ' Name: Printer Word Wrap ' Description:The Multiline Text Box or ' the Rich Text Box offers the ability to ' automatically word wrap long text at word boundaries, but no such feature exists when it is time to output that text to the printer. 3 possible solutions are presented here. ' By: J.A. Coutts ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None 'This code is copyrighted and has limite ' d warranties. 'Please see http://www.Planet-Source-Cod ' e.com/xq/ASP/txtCodeId.74586/lngWId.1/qx ' /vb/scripts/ShowCode.htm 'for details. '************************************** --------------------------------------------------------- Option 1 - Use the Microsoft recommended solution: http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q146/0/22.asp&NoWebContent=1 This option is complex and lengthy, but does control the printer margins. --------------------------------------------------------- Option 2 - Use something similar to what I developed: 'TextIn is the RichTextBox object, and i ' Len is the line length desired Function WordWrap(TextIn As Object, iLen As Integer) As Variant Dim lStart As Long Dim lEnd As Long Dim N% Dim OutArray() As String lStart = 1 'Make sure string is not zero length TextIn.Text = Trim(TextIn.Text) If Len(TextIn.Text) = 0 Then TextIn.Text = " " ReDim OutArray(Len(TextIn.Text) / iLen) With TextIn Do Until lStart >= Len(.Text) 'Find actual end of line lEnd = InStr(lStart, .Text, vbCrLf) If lEnd - lStart < iLen Then 'Line ends with CrLf within current line .SelStart = lEnd + iLen + 2 Else .SelStart = lStart + iLen End If If .SelStart - lStart >= iLen Then 'line wraps, find preceding space .UpTo " ", False End If 'If there are no spaces If .SelStart < lStart Then .SelStart = lStart + iLen OutArray(N%) = Mid$(.Text, lStart, .SelStart - lStart) 'Debug.Print OutArray(N%) N% = N% + 1 lStart = .SelStart + 1 Loop End With ReDim Preserve OutArray(N% - 1) WordWrap = OutArray End Function This option returns a variant array and only works with fixed width fonts such as Courier New or Arial. There is no guarantee that it is bug free, but it offers the ability to precede and follow with other printer instructions. --------------------------------------------------------- Option 3 - Use the .SelPrint method in conjuction with a RichTextBox Control and a Common Dialog control: CMDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums If RichTextBox1.SelLength = 0 Then CMDialog1.Flags = CMDialog.Flags + cdlPDAllPages Else CMDialog1.Flags = CMDialog.Flags + cdlPDSelection End If CMDialog1.ShowPrinter Printer.Print "" RichTextBox1.SelPrint CMDialog1.hDC This option is by far the simplest and most elegant. The disadvantage is that youare stuck with only what is in the formatted RichTextBox, but even if you have to add text to the box before printing, and replace it with the original after, it is straight forward and simple. ---------------------------------------------------------