#1
|
|||
|
|||
Title case macro gets a "type mismatch" error at the Instr method
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 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 Thank you, Marc |
#2
|
||||
|
||||
Use:
Code:
If InStr(1, sUpper_case_ls, sTest, vbTextCompare) = False Then
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Type mismatch error | abenitez77 | Excel Programming | 7 | 04-04-2019 08:51 AM |
Error in macro "Ambiguous name detected" - but why?? | Officer_Bierschnitt | Excel Programming | 7 | 11-30-2015 03:55 AM |
Error: "Changes made were lost...reconnect with server", when switching "from" field | randhurrle | Outlook | 2 | 02-25-2015 06:51 PM |
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas | jocke321 | Word VBA | 2 | 12-10-2014 11:27 AM |
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) | tinfanide | Excel Programming | 1 | 03-29-2012 09:10 AM |