Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub countWordsSpecial()
- wholetext = ActiveDocument.range(Selection.range.start, Selection.range.End)
- While InStr(wholetext, Chr(13))
- wholetext = Replace(wholetext, Chr(13), " ")
- Wend
- While InStr(wholetext, " ")
- wholetext = Replace(wholetext, " ", " ")
- Wend
- Dim arr() As String
- arr() = Split(wholetext, " ")
- Dim tmp As String
- Dim wordcount As Long
- braceDepth = 0
- wordcount = 0
- For Each element In arr()
- tmp = element
- If (Not "" = tmp) Then
- If StartsWith(tmp, "[[") Then
- braceDepth = braceDepth + 1
- ElseIf EndsWith(tmp, "]]") Then
- braceDepth = braceDepth - 1
- ElseIf (braceDepth = 0) Then
- wordcount = wordcount + 1
- End If
- End If
- Next element
- MsgBox wordcount
- End Sub
- Public Function EndsWith(str As String, ending As String) As Boolean
- Dim endingLen As Integer
- endingLen = Len(ending)
- EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))
- End Function
- Public Function StartsWith(str As String, start As String) As Boolean
- Dim startLen As Integer
- startLen = Len(start)
- StartsWith = (Left(Trim(UCase(str)), startLen) = UCase(start))
- End Function
Advertisement
Add Comment
Please, Sign In to add comment