Thread: Bookmarks
View Single Post
 
Old 06-28-2015, 07:09 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Assuming you have a complete paragraph bookmarked, the following should work:
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim BmkNm As String, BmkRng As Range, Tbl As Table

    With ActiveDocument
        If .Bookmarks.Exists("Text") Then
            Set BmkRng = .Bookmarks("Text").Range
            With BmkRng
                Select Case CC.Tag
                    Case Is = "Tagname"
                        Select Case CC.Range.Text
                            Case Is = "Hi"
                                .Text = ""
                            Case Is = "Welcome"
                                Set Tbl = ActiveDocument.Tables.Add(Range:=BmkRng, NumRows:=7, NumColumns:= _
                                                                    2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
                                                                    wdAutoFitFixed)
                                With Tbl
                                    .Cell(1, 1).Range.Text = "Text 1"
                                    .Cell(2, 1).Range.Text = "Text 2"
                                    .Cell(2, 1).Range.Font.Bold = True
                                    .Cell(3, 1).Range.Text = "Text 3"
                                    .Cell(4, 1).Range.Text = "Text 4"
                                    .Cell(5, 1).Range.Text = "Text 5"
                                    .Cell(6, 1).Range.Text = "Text 6"
                                    .Cell(7, 1).Range.Text = "Text 7"
                                End With
                                Tbl.Range.Next.InsertBefore vbCr
                                .End = Tbl.Range.End + 1
                            Case Is = "Hello"
                                .Text = "  Some new Text: " & vbCr
                            Case Else
                                GoTo ErrExit
                        End Select
                End Select
            End With
            .Bookmarks.Add "Text", BmkRng
        Else
            MsgBox "Bookmark not found."
        End If
    End With
ErrExit:
    Set BmkRng = Nothing: Set Tbl = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote