trying to format text in MS Word using Visual Basic (Using Visual Studio 2017

Maslow Raffo
Maslow Raffo used Ask the Experts™
on
I'm trying to format text in MS Word using Visual Basic (Using Visual Studio 2017) and can only find examples in C# on the web.

Can you point me to a few links that show how to manipulated text in a Word doc with VB (alignment, bold, etc)?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Director of Technology Development, IPM
Commented:
Here's some code to get you started ... Open a VB project and add a reference to the Microsoft Word COM object.
Then add the following code:

        Dim objWordApp As Microsoft.Office.Interop.Word.Application
        Dim objWordDoc As Microsoft.Office.Interop.Word.Document
        Dim textRange As Microsoft.Office.Interop.Word.Range

        objWordApp = New Microsoft.Office.Interop.Word.Application
        objWordApp.Visible = True
        objWordDoc = objWordApp.Documents.Add

        objWordDoc.Content.InsertAfter("Experts Exchange")
       
       ' select the range you want to operate on - here it's the first paragraph
        textRange = objWordDoc.Paragraphs(1).Range
        textRange.Font.Size = 14
        textRange.Font.Bold = True
        textRange.Font.Italic = True
        textRange.ParagraphFormat.Alignment =   Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter

Open in new window

Author

Commented:
Ok, this works, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial