Finding a word and/or variable in Word Document and changing font to Bold

This topic contains 0 replies, has 1 voice, and was last updated by  Long S 2 years, 1 month ago.

  • Author
  • #38582

    Long S

    I have a script where I am replacing a bookmark in a word document with text from a xml.

    I have hard coded a few words into the word document via the bookmark properties. I am trying to turn the font of the strings I hardcoded into the document into bold and increase the font size

    StigData is predefined earlier in my script... The script works fine its just not bolding the font.
    $template = "Template.docx"
    $wd = New-Object –comobject Word.Application

    foreach ($stigDataItem in $stigData)
    $title = $stigDataItem.title
    $check = $'check-content'
    $ft = $

    $doc.Bookmarks.Item("AllStigInfo").Range.Text ="FixText" + "`r`n" + $ft + "`r`n" +"`r`n"
    $doc.Bookmarks.Item("AllStigInfo").Range.Text ="Check Content" + "`r`n" + $check + "`r`n"
    $doc.Bookmarks.Item("AllStigInfo").Range.Text =$title + "`r`n"


    $selection = $wd.selection
    $selection.Font.Bold = $True
    $stringcheck = "Check Content"

    Remove-Variable wd

    I attempted to select the words I need to replace and replace it with a bold font with the section:
    $selection = $wd.selection
    $selection.Font.Bold = $True
    $stringcheck = "Check Content"

    However that just added a bold word to the document.

    I am trying to bold everywhere that says FixText, Check Content, and $title. Also making $title a bigger font.

    Also tried referring to but it didn't work out for me.

You must be logged in to reply to this topic.