Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>It's possible. Assuming the input file is available at <code>c:\test.txt</code>. Containing the input text.</strong></p> <p><strong><em><code>The module</code></em></strong></p> <pre><code>Option Explicit 'requires Microsoft Scripting Runtime Public Sub test() Dim fields(5) As String fields(0) = vbNullChar fields(1) = vbNullChar fields(2) = """CG44_CLIFOR""" fields(3) = vbNullChar fields(4) = vbNullChar fields(5) = "6" Dim fpath$, x fpath = "c:\test.txt" x = Join(GetBlock(fpath, fields), vbCrLf &amp; vbCrLf &amp; vbCrLf) MsgBox x End Sub Public Function GetBlock(fpath$, textArr As Variant) As Variant Dim results As Variant Dim fso As New Scripting.FileSystemObject Dim re As New VBScript_RegExp_55.RegExp If UBound(textArr) &lt;&gt; 5 Then MsgBox "Invalid data provided!" Exit Function End If Dim fields(5) As String fields(0) = "Height += +" fields(1) = "Left += +" fields(2) = "DBField += +" fields(3) = "Caption += +" fields(4) = "Object\.Tag += +" fields(5) = "MaxWidth += +" Dim p&amp;, validPos$ p = 0 For p = LBound(fields) To UBound(fields) If textArr(p) &lt;&gt; vbNullChar Then fields(p) = fields(p) &amp; EscapeString(CStr(textArr(p))) validPos = validPos &amp; CStr(p) &amp; "|" End If Next p Dim content$, result As Boolean, outText$ content = fso.OpenTextFile(fpath).ReadAll() outText = vbNullChar With re .Global = True .IgnoreCase = True .MultiLine = False .Pattern = "--[\s\S]+?(?=--)" If .test(content) = True Then Dim m, posz posz = Split(validPos, "|") result = True Dim mt As Match, mts As MatchCollection Set mts = .Execute(content) For Each mt In mts outText = mt.Value Dim po For Each po In posz If po &lt;&gt; "" Then m = fields(CStr(po)) .Pattern = m result = .test(outText) End If Next po For Each m In fields Next m If result = True Then results = results &amp; "&lt;cylian/&gt;" &amp; outText End If Next mt Else result = False End If End With GetBlock = Split(results, "&lt;cylian/&gt;", -1, vbBinaryCompare) End Function Private Function EscapeString(str$) As String 'some general replaces Dim a$ a = str a = Replace(a, """", """""") a = Replace(a, ".", "\.") a = Replace(a, "}", "\}") a = Replace(a, "{", "\{") a = Replace(a, ")", "\)") a = Replace(a, "(", "\(") a = Replace(a, "+", "\+") a = Replace(a, "*", "\*") a = Replace(a, "-", "\-") a = Replace(a, "\", "\\") a = Replace(a, "^", "\^") a = Replace(a, "$", "\$") EscapeString = a End Function </code></pre> <p><strong><em><code>The calling (from immediate window)</code></em></strong></p> <pre><code>test </code></pre> <p><strong><em><code>The outcome</code></em></strong></p> <p><img src="https://i.stack.imgur.com/CRS4S.png" alt="enter image description here"></p> <p><strong>Hope this helps.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload