View Single Post
 
Old 09-26-2022, 10:36 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,988
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

xlDown is the name of a constant that only has a value to Excel's vba. You loaded the Excel Application as an object (late binding) so your code is unable to use the Excel constants directly. If you replace it with its actual value (-4121) the line of code should work.
Code:
Set rng = ws.Range("B3", ws.Range("B3").End(-4121))
With the EMBOLD code, there is a trick to doing both a text replacement AND a formatting change - you can't do this in a single step. So after replacing the text, your second pass needs to find the new text and make it bold
Code:
Sub EMBOLD_NEC_LIST(findText As String, replaceText As String)
  With ActiveDocument.Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = findText
    .Replacement.Text = replaceText
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    .Text = replaceText
    .Replacement.Text = ""
    .Replacement.Font.Bold = True
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 09-27-2022 at 04:25 PM.
Reply With Quote