I can't figure out you I get a "type mismatch" error at the Instr method in my macro.
The following is the code:
Code:
Sub subTitleCase() 'Source = NMc
ActiveDocument.ActiveWindow.Activate
ActiveDocument.ActiveWindow.SetFocus
Dim strActiveDocFullName As String
strActiveDocFullName = fn01.fnIterateAndSelectWindow
Dim lclist As String
Dim wrd As Integer
Dim sTest As String
Dim sUpper_case_ls As String
With ActiveDocument
End With
sUpper_case_ls = "MD" & ", " & "MD," & ", " & "M.D." & ", " & "M.D.," & ", " & "Ph.D." & _
", " & "Ph.D.," & ", " & "PhD" & ", " & "PhD," & ", " & "DDS" & ", " & "DDS," & _
", " & "D.D.S." & ", " & "D.D.S.," & ", " & "ROA" & ", " & "ROA,"
With ActiveDocument
' list of lowercase words, surrounded by spaces
lclist = " of the by to this is from a "
Selection.Range.Case = wdTitleWord
For wrd = 2 To Selection.Range.Words.Count
sTest = Trim(Selection.Range.Words(CStr(wrd)))
sTest = " " & LCase(sTest) & " "
If InStr(sUpper_case_ls, sTest, vbTextCompare) = False Then
MsgBox "sTest = " & sTest & vbCrLf & sTest & " is not in sUpper_case_ls" & _
"sUpper_case_ls = " & sUpper_case_ls
Selection.Range.Words(wrd).Case = wdLowerCase
Else ' If InStr(lclist, sTest) = False Then
Selection.Range.Words(wrd).Case = wdUpperCase
End If ' If InStr(lclist, sTest) = False Then
Next wrd ' For wrd = 2 To Selection.Range.Words.Count
End With ' With ActiveDocument
End Sub ' subTitleCase
I don't get the "type mismatch" error if I omit the vbTextCompare option.
I should be able to use the "vbTextCompare" option, according to Office VBA Reference:
HTML Code:
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/instr-function
Any insights about what I did wrong would be much appreciated.
Thank you,
Marc