Word 2007 vba - Styles arent applied via macro -
I have a macro code, which basically creates some tables, then some type into some text, And then some text placeholder problem appears when I try to apply the styles in the text. At first I thought that this is only a placeholder not affected by the code but it seems that the regular text selected by the macro also does not apply.
The code basically looks like this:
Selection.TypeText Text: = "Entreprisecost:" Selection.MoveRight Unit: = wdCell CC = Selection.Range. ContentControls.Add (wdContentControlText) cc.SetPlaceholderText Text: = "Details of cost" cc.DefaultTextStyle = "EnterpriseStyle" Selection.Style = ActiveDocument.Styles ("EnterpriseStyle")
Note I How to define style on both placeholders and selection.
Next, I try to enter a simple macro where I try to enter the whole selection, then apply the selection to the style. It works when I'm recording but after running the macro it does not work It's weird:
Selection.MoveUp unit: = wdLine, count: = 5, increase: = wdExtend Selection.Style = ActiveDocument.Styles ("ExperienceStyle")
< / Pre>Why is this happening? My macro security settings are set to the default medium, but I definitely make sure to enable macros after the template has been opened. This is when I open both templates and when I click it twice to create a new document based on the template any idea?
Edit: In addition to applying styles, the code applied to every bit style of macro functions is run, the text does not change. And when I select that style to choose the text, then I can see that the style applies. But it is not at the same time. Strange, if I select the text, manually repeat the style again, which means, clicking on the style already selected, then I think the style is actually implemented.
It's like the style is being set without being implemented in fact.
First of all, you have to help us with code and set up. I think you have at least one six tables with selection in cell 6,1 (bottom, left cell). Second, we do not anticipate what the variables are; Use Dim Statement Third, we do not have your style, so I have them standard Normal
With it, your code works fine below. I can see that only one wrong thing is that you have used ExperienceStyle in the first part and EnterpriseStyle in the previous part. If you get an error, then either one would not have existed.
public sub-test (Selection.TypeText text): "Entreprisecost:" Selection.MoveRight Unit: = wdCell Moder CC ContentControl Set Selection.Range.ContentControls.Add (wdContentControlText) cc.SetPlaceholderText in the form of CC: cc.DefaultTextStyle = "Title" Selection.Style = ActiveDocument.Styles ("Title") Selection.Style = ActiveDocument.Styles "Cost The details of "change" ("strong") is changing the style of Selection.MoveUp Unit: = wdLine, Count: = 5, Increase: = wdExtend Selection.Style = ActiveDocument.Styles ("Strong") End Sub
< / Pre>
Comments
Post a Comment