My word document has styles created, for example My_Style (which i use for titles). I want to create entries to illustrations that get the correlative number from that style.
I have this code:
Sub Macro4()
'
' Macro4 Macro
'
'
With CaptionLabels("Illustration")
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 2
.Separator = wdSeparatorHyphen
End With
Selection.Style = ActiveDocument.Styles("My_Style")
Selection.InsertCaption Label:="Ilustración", TitleAutoText:= _
"InsertTitle4", Title:="", Position:=wdCaptionPositionAbove, _
ExcludeLabel:=0
End Sub
The result says Illustration¡Error!.
I think the error is that the macro iscreating the entries with the Style Title1 from word but i dont have any text with that style because i am using my own created styles.
I don't know where can i especify that i want to use my style to create the entries.
Thank you.
Selection.Style = ActiveDocument.Styles("My_Style")
does that. Whatever relationship the code before and after this line has on your intention isn't clear. I think you will make progress faster if you start with declaring a range and then manipulate that range. For example,Dim Rng As Range
andSet Rng = Selection.Range
. Perhaps, next you may want to add the caption in that range, perhaps at its end, then format the caption, and apply the style to it. – Variatus