Function Formats Justifies Class ★ Top 20 Most Useful

WrapText

Wrap the lines of text within each paragraph so that each line is no longer that the specified maximum width.

Signature (Visual Basic / VBA)

Public Function WrapText( _
      ByVal vParagraphs As Variant _
    , ByVal vMaxWidth As Variant _
    , Optional ByVal vJustifyCodes As Variant _
    , Optional ByVal vSeparator As Variant _
    ) As Variant

Code Example

    ? WrapText(Preamble, 40)
    We the people of the United States, in
    order to form a more perfect union,
    establish justice, insure domestic
    tranquility, provide for the common
    defense, promote the general welfare,
    and secure the blessing of liberty to
    ourselves and our posterity, do ordain
    and establish the Constitution of the
    United States of America.

Parameters

Parameter Description
vParagraphs String containing one or more paragraphs of text whose lines should be wrapped so that they fit within some maximum line length. The individual paragraphs of text in string vParagraphs can be separated by either line feed or carriage return line feed strings. Function returns Null if vParagraphs is Null or cannot be fixed up to a String.
vMaxWidth The maximum width of the lines in the result string. Function returns Null if vMaxWidth is Null or cannot be fixed up to a number.
vJustifyCodes Any meaningful combination of the formatting codes available through the Justify properties of this Class. Defaults an empty string (the absence of any specific formatting codes) if vJustifyCodes is missing or Null or cannot be fixed up to a String.
vSeparator The string which will separate the lines of text in the result string. vSeparator defaults to carriage return and new line characters if it is missing or Null or cannot be fixed up to a String.