Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2020, 08:42 PM
marceepoo marceepoo is offline Title case macro gets a "type mismatch" error at the Instr method Windows 7 64bit Title case macro gets a "type mismatch" error at the Instr method Office 2010 64bit
Novice
Title case macro gets a "type mismatch" error at the Instr method
 
Join Date: Sep 2012
Posts: 22
marceepoo is on a distinguished road
Default 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 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
Reply With Quote
  #2  
Old 03-05-2020, 09:41 PM
macropod's Avatar
macropod macropod is offline Title case macro gets a "type mismatch" error at the Instr method Windows 7 64bit Title case macro gets a "type mismatch" error at the Instr method Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Use:
Code:
If InStr(1, sUpper_case_ls, sTest, vbTextCompare) = False Then
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft