I have a macro code that basically creates a few tables, then types in some text in some of then, and then places a few text placeholders. The problem appear when I try to apply styles to the text. At first I thought it was only the placeholders that aren't affected by the code. But it seems as though regular text, selected by the macro isn't applied as well.
The code basically looks like this:
Selection.TypeText Text:="Entreprisecost:"
Selection.MoveRight Unit:=wdCell
Set cc = Selection.Range.ContentControls.Add(wdContentControlText)
cc.SetPlaceholderText Text:="Description of the cost"
cc.DefaultTextStyle = "EnterpriseStyle"
Selection.Style = ActiveDocument.Styles("EnterpriseStyle")
Notice how I define the style on both the placeholder AND the selection.
Next, I tried to record a simple macro where I select the entire row, then apply the style to the selection. This works when I'm recording. But it doesn't work when I run the macro. It's strange:
Selection.MoveUp Unit:=wdLine, Count:=5, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("ExperienceStyle")
Why is this happening? My macro security settings are set to default medium, but I choose of course to enable macros once the template is opened. This happens when I both open the template itself and when i doubleclick it to create a new document based on the template. Any ideas?
Edit: Every bit of the macro works, besides applying styles. The code that applies the style is run, the the text doesn't change. And when I select the text to check which style its in, I can see that the style is applied. But it isn't at the same time. Strange, if I select the text, then manually reapply the style, meaning, clicking on the same style that's already selected, THEN I see that the style is really applied.
It's like the style is being set without it actually being applied.