Using the Trim function under certain circumstances doesn’t show any difference in the ‘Watches’ value or Immediate window.
Here’s an example sentence that can be copied into a document to show what I mean:
A MAN AND ANOTHER IN THE HOUSE ARE GOING TO THE TOWN.
And here’s a macro to use with it:
Code:
Sub Macro13()
For Each wrd In ActiveDocument.Words
Select Case Trim(wrd)
Case "A", "AND", "OF", "IN", "IS", "TO", "THE"
wrd.Case = wdLowerCase
End Select
Next wrd
End Sub
Trimming doesn't show any difference in the ‘Watches’ list value of “wrd”, nor by using Debug.Print to the Immediate Window (i.e. the selected word still shows as having a trailing space: “A ” instead of “A”, and “THE ” instead of “THE”); but it (using the Trim function) certainly makes a difference because otherwise the relevant words aren't selected / modified / lowercased. That is, if you change the line, “Select Case Trim(wrd)”, to “Select Case wrd”, then the macro does nothing, even though the value of “wrd” in the ‘Watches’ list is exactly the same in both versions (i.e. with or without ‘Trim’ being used).
It seems that “wrd”
is being trimmed but it isn’t showing in the Watch list or Immediate window, which appears unusual to me. More than likely this has to do with “wrd” being listed as type “Variant/Object/Range”, whereas the Trim function (as far as I know) is only for use with strings; but I still don’t understand why, or even how, it’s being trimmed but not trimmed (as it seems) at the same time. Anyone?