View Single Post
 
Old 07-19-2024, 02:40 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Hello,


When you post code, it is helpful to simply post a snippet of the part that doesn't work. That way we don't have to try to recreate your entire situation (create and excel file etc.).


Try:


Code:
Sub format_scientific_names()
Dim oRng As Range
Dim strFind As String
  strFind = "Hyla cinerea"
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = strFind
    .Forward = True
    .Wrap = wdFindStop
    .MatchCase = False
    While .Execute
      oRng.Font.Italic = True
      oRng.Font.Bold = True
      oRng.Font.Color = RGB(200, 187, 0)
      oRng.Font.Name = "Times New Roman"
      oRng.Case = wdLowerCase
      oRng.Words(1).Characters(1).Case = wdUpperCase
      oRng.Collapse wdCollapseEnd
    Wend
  End With
  End Sub

Or you could simply use your Excel file "Find" phrase as the replacement text:


Code:
Sub format_scientific_names()
Dim oRng As Range
Dim strFind As String
  strFind = "Hyla cinerea"
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = strFind
    .Forward = True
    .Wrap = wdFindStop
    .MatchCase = False
    While .Execute
      oRng.Text = strFind
      oRng.Font.Italic = True
      oRng.Font.Bold = True
      oRng.Font.Color = RGB(200, 187, 0)
      oRng.Font.Name = "Times New Roman"
      oRng.Collapse wdCollapseEnd
    Wend
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote