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 Profile photo of Long S Long S 4 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #38582
    Profile photo of Long S
    Long S
    Participant

    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
    $doc=$wd.documents.Add($template)

    foreach ($stigDataItem in $stigData)
    {
    $title = $stigDataItem.title
    $check = $stigDataItem.group.Rule.check.'check-content'
    $ft = $stigDataItem.group.rule.fixtext.innerxml

    $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"
    $selection.TypeText($stringcheck)

    $doc.SaveAs([ref]$newfile)
    $doc.Close()
    $wd.Quit()
    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"
    $selection.TypeText($stringcheck)

    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 https://blogs.technet.microsoft.com/heyscriptingguy/2006/02/01/how-can-i-boldface-a-specific-word-throughout-a-microsoft-word-document/ but it didn't work out for me.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.