superfurryanimals
superfurryanimals

Reputation: 177

How to add style programmatically to Word document

I have a dynamically created textbox that opens in Word. I am trying to give it one of the default styles in Word 2010 ("Colored Fill, White Outline - Accent 1) however I have not been able to find the code to do this.

Below is what I have so far, which creates and offsets the textbox:

oDoc = oWord.Documents.Add
Dim titleBanner As Word.Shape
titleBanner = oDoc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 81.0#, 20.5, 456.75, 24.75)
titleBanner.TextFrame.TextRange.Text = "This is a textbox!"

Upvotes: 0

Views: 2329

Answers (2)

Michael Cavalier
Michael Cavalier

Reputation: 11

Here is what I did:

  1. Open Word
  2. Start record a macro
  3. Perform a find and replace from a color in my document to the color that I want
  4. Stop recording the macro
  5. Open the VBA macro
  6. Find the integer value for the color
  7. Replace -738148353 in the example statement below with your value:

    selection.Font.Color = (Microsoft.Office.Interop.Word.WdColor)(-738148353);

Upvotes: 1

Micah Armantrout
Micah Armantrout

Reputation: 6971

Take a look at

http://docx.codeplex.com/

you won't need to use Com and it allows you to do formating as well

Upvotes: 1

Related Questions