how to insert html into a wordDoc Openxml

I have a word document with rich text controls with specific Title/Tags.
I would like to insert text into those controls using the openxml sdk and, however my text is html formatted lets say <b>some text </b>
If i do the following
 sdtElement.Descendants(Of Text)().FirstOrDefault().Text = "<b> some text </b>"
I see the <b></b> as text, what I would like to happen is have this text in bold.
What control should I use and How would I achieve what I want
Here's the code I am using

Using doc As WordprocessingDocument = WordprocessingDocument.Open("C:\Test.docx", True)
            Dim mainPart As MainDocumentPart = doc.MainDocumentPart()
            Dim sdtElement As SdtElement = mainPart.Document.Descendants(Of SdtElement)().Where(Function(element) element.SdtProperties.GetFirstChild(Of SdtAlias)() IsNot Nothing _
                                 AndAlso element.SdtProperties.GetFirstChild(Of SdtAlias).Val = "test").SingleOrDefault()
            If sdtElement IsNot Nothing Then
                sdtElement.Descendants(Of Text)().FirstOrDefault().Text = "<b> some text </b>"
            End If
        End Using

Open in new window

Who is Participating?
xav056Connect With a Mentor Author Commented:
using ltchunck seems to be the solution
Hi Xav

This would be one way to do it: but it only deals with bold and italics!  Beyond that, you'd need an HTML to RTF library.  There are commercial products like or if you Google you might find an open source library on somewhere like CodePlex.
xav056Author Commented:
this uss vba or com,
I am looking for ways to do this using the openxml sdk, without a word com object
Thank you
Thanks for sharing the solution altChunk - I've learned something new!
xav056Author Commented:
this seems to be the solution I am looking for, found it myself
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.