VBA code in word doc (finding/replacing strings in excel list) not updating to sentence case; other formatting works well

I have a VBA macro (code from the internet) that pulls scientific names from an excel sheet (sheet1, range A) and finds/replaces the s.names in the word document with the terms in the excel sheet. The code is supposed to change the font to bold, italic, color, and font type (Times new roman) and this portion works well. What doesn’t work is changing the scientific names to sentence case, i.e. hyla cinerea or Hyla Cinerea or some other variant should be Hyla cinerea.

I’ve tried testing with other functions (e.g., wdUpperCase and wdLowerCase, https://learn.microsoft.com/en-us/office/vba/api/word.wdcharactercase) which work, but are not the desired output. wdTitleSentence is what I want but when the code is run, it doesn’t throw an error and the other formatting is still applied, but nothing changes with the text case unless it’s in all caps, and then it goes to all lowercase.
I also considered writing a function similar to some of the suggestions here: https://www.vbforums.com/showthread.php?847469-RESOLVED-First-letter-in-capital-letter
but I’m not super savvy with VBA, so not sure if there is another existing function that exists that will accomplish this, or something else needs to occur. I did find Excel VBA Sentence Case Function and Converting to sentence case using VBA as potential help, but not sure how to incorporate this into the existing code. I will mention that the text in the excel has the desired case, so if there’s a way to inherit the case from the excel file (and/or other formatting for that matter), that would be great. TIA for the help and I’m a first time poster, so apologies if this isn’t correctly formatted.

VBA word code that works except for changing the case:

Sub format_scientific_names()
Dim xlapp As Object
Dim xlbook As Object
Dim xlsheet As Object
Dim myarray As Variant
Dim FD As FileDialog
Dim strSource As String
Dim i As Long, lognum As Long
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
.Title = "Select the workbook that contains the terms to be italicized"
.Filters.Clear
.Filters.Add "Excel Workbooks", "*.xlsx"
.AllowMultiSelect = False
If .Show = -1 Then
strSource = .SelectedItems(1)
Else
MsgBox "You did not select the workbook that contains the data"
Exit Sub
End If
End With
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bstartApp = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlbook = xlapp.Workbooks.Open(strSource)
Set xlsheet = xlbook.Worksheets(1)
myarray = xlsheet.Range("A1").CurrentRegion.Value
If bstartApp = True Then
xlapp.Quit
End If
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
For i = LBound(myarray) To UBound(myarray)
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
    Do While .Execute(FindText:=myarray(i, 1), Forward:=True, _
    MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=False) = True
    Set rng = Selection.Range
    Selection.Collapse wdCollapseEnd
    rng.Font.Italic = True
    rng.Font.Bold = True
    rng.Font.Color = RGB(200,187,0)
    rng.Font.Name ="Times New Roman"
    rng.Case=  wdTitleSentence 'wdUpperCase works; this doesn't; something else I could put here?
    Loop
    End With
 Next i
End Sub

New contributor

B13 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật