Function String Extras Class ★ Top 20 Most Useful

StripVBComments

"Strip Visual Basic Comments" Strip the comments from a string representing a line of Visual Basic code. Returns a string containing everything but the comment portion of a line of Visual Basic source code.

Signature (Visual Basic / VBA)

Public Function StripVBComments( _
      ByVal vLine As Variant _
    , Optional ByVal vKeepCopyrights As Variant _
    ) As Variant

Code Example

    StripVBComments("    ' Assignment.") = "    "
    StripVBComments("    lngNum = 45 ' Assignment.") = "    lngNum = 45 "
    StripVBComments("    lngNum = 45") = "    lngNum = 45"
    StripVBComments("    ' Copyright Entisoft") = "    "
    StripVBComments("    ' Copyright Entisoft", True) = "    ' Copyright Entisoft"

Parameters

Parameter Description
vLine The string containing a line of Visual Basic source code. Function returns Null if vLine is Null or cannot be fixed up to a String.
vKeepCopyrights Determine whether comments containing copyright notices should be retained. If True, then any comments containing the strings "(C)", "Copr", and "Copyright" will be retained. vKeepCopyrights defaults to False if it is missing or Null or cannot be fixed up to a number.