excel vba - VBA Writing to Word, changing font formatting -


I am writing a VBA script in Excel in the output text based on some tables in the Word document. For the most part everything is working properly (I'm reading myself because I go with a lot of help from Stack Overflow). I've got a very long code, so it will be difficult to copy it here, I'll try and show the proper parts.

The issue I am running is trying to change the formatting. As I am running, I have created some different styles to help standardize formatting options, .Styles.Add ("SectionHeader") with

  wrddoc .Styles.Add ("NoFormat") .Styles.Add ("Direct") .Styles.Add ("Failed") .Styles.Add ( "Unknown") .Styles ("section header") with .Styles.Add ("bold") .Font.Name = "Calibri" .Font. Size = 12 .Font.Underline = True font.Bold = False .Font. Italic = False .Font. Strikethrough = False .Font. Subscribe = False .Font.Superscript = False Finish with .font.color = RGB (0, 0, 0). ("No format") .fonts .name = "calibrary" .font.Size = 12 .Font .interval line = wrong .font Bold = incorrect .Font.Italic = False .Font.Strikethrough = false .Font.Subscript = False .Font.Superscript = False .Font. Color = RGB ends with (0, 0, 0). Style ("marginal"). FontName = "Calibri" .Font.Size = 12 .Font.Underline = False .Font.Bold = True .Font.Italic = False. Font Strikethrough = False. Membership = False .Font.Superscript = False .Font. Tyles ("Failed") with Color = RGB (0, 0, 255) along with the end. Name = "calibrary" .Font.Size = 12 .Font. Ease = true .Font.Bold = True .Font.Italic = False .Font. Strikethrough = False .Font. Subscript = False .Font.Superscript = False .Font.Color = RGB (255, 0, 0) with interval. ("Unknown") .Font.Name = "Calibri". Font.Size = 12 .Fonts .Uncaped = False Font.Bold = True .Font.Italic = False .Font. Strikethrough = False .Font. Subscript = False .Font.Superscript = False .Font. Color = RGB ends with (0, 176, 80). Style ("bold") .Font.Name = "Calibri" .Font.Size = 12 .Font.Underline = False .Font.Bold = True .Font. Italic = False Font Strikethrough = False. Subscribe = False .Font.Superscript = false .Font.Color = RGB (0, 0, 0) end with end   

Then, I'm trying to do this where the output In the text there will be a word between the sentence change format,

  with wrdApp Selection. Style = wrdDoc.Styles ("NoFormat"). Light text: = "This sentence is the beginning" .Style = wrdDoc .Styl Es ("unknown"). Published text: = "unknown" .Style = wrdDoc.Styles (" NoFormat ") .light text: =" so we will keep trying ... "with type end   

but whatever I get is without any change The sentence is, the format of that word.

More curiously, I also have some components that should apply my "bold" style to the whole sentence, one of which applies bold, which does not do the other,

  with wrdApp Selection. Style = wrdDoc.Styles ("bold"). Light text: = "This is not a work" end with wrdApp. Selection. Style = wrdDoc.Styles ("bold"). Light text: = "This one works!"   

I also want to be able to apply

 . Paragraph formatting SpaceAfter = 0 Paragraph format.pace = first <0>  

to select some of these, but I can not understand how to do this. I can get it for the "range" in the document, but it ends up applying the existing sections of that document, but none of the new lessons.

You have a problem that when you create style, this paragraph style is by default ( Or in recent versions of the word) is usually a "linked style", sometimes called paragraph / character styles).

So when you execute

 . Style = wrdDoc.Styles ("NoFormat")   

For the second time, for example, the style applies to the entire paragraph The fact is that you try to apply the "unknown" of the paragraph Have done

If you create the same test styles as character styles, for example

 .  

And so on "unknown" style

And to run your first test example again, you should see the difference "no format", wdStyleType.wdStyleTypeCharacter

add more.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -