Pavi S

Pavi S

  • NA
  • 41
  • 74k

how to Insert Content Control with NewStyle in VBA

Jul 5 2012 11:45 PM

Im trying to create new style for content control but its showing error "Could not apply the style".
the default style coming for the content control is "Default paragraph font".

i want to change with my new style.please any one help.


my code
---------
Dim ran As range
    Dim con As ContentControl
    Set ran = Selection.range.Duplicate
    Set con = ran.ContentControls.Add(wdContentControlRichText)
    con.Tag = Tag
    con.Title = Title
    
    If Not StyleExists1(StyleName) Then
    Select Case StyleName

               Case "Corres":
                     WordBasic.FormatStyle name:=StyleName, Type:=0, NextStyle _
                     :="Correspondence"
                     With ActiveDocument.Styles(StyleName).Font
                        .name = "NewsGothicBT-Bold"
                        .Size = 9
                        .Bold = True
                     End With
                     With ActiveDocument.Styles(StyleName).ParagraphFormat
                        .Alignment = wdAlignParagraphLeft
                        .SpaceAfter = 13
                      End With
    End If
        con.range.Select
        Selection.ParentContentControl.DefaultTextStyle = StyleName
        con.DefaultTextStyle = StyleName
        con.LockContentControl = True