Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 06-28-2015, 05:59 AM
Schildkröte Schildkröte is offline Bookmarks Windows 8 Bookmarks Office 2013
Novice
Bookmarks
 
Join Date: Jun 2015
Posts: 6
Schildkröte is on a distinguished road
Default

Thanks a lot for your solution.
I tried it and it works but I have some problems with a new line.
Heres my modified code:

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"
        .Delete
        .Text = ""
      Case Is = "Welcome"
        .Delete
        .InsertBefore " " & vbCr
        Set Tbl = .Tables.Add(Range:=.Characters.Last, 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
        .Start = Tbl.Range.Start - 2
        .Characters.First.InsertBefore " "
        .End = Tbl.Range.End + 1
        .Characters.Last.InsertAfter vbCr & "  "
      Case Is = "Hello"
        .Delete
        .Text = vbCr & "  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
When I choose "Welcome" everything works fine. But when I then choose "Hi" or "Hello", there is an empty line which doesnt belong to the bookmark.
I suppose this is because I add a new line after the end of the bookmark in "Welcome".
Is there a way to extend the bookmark so that this new line is deleted when I choose something else?

By the way: In my document there are two blank spaces at the beginning of each line..

Thanks for helping
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bookmarks Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Bookmarks TOC hyperlinks and bookmarks. GregCFII Word 9 03-02-2014 06:43 AM
Can't See Bookmarks bobmayo Word 21 06-04-2013 07:37 AM
Bookmarks Table of Bookmarks Niy Word 3 03-28-2012 12:18 AM
Bookmarks for a PDF? Ownaholic Word 0 10-30-2010 12:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft