![]() |
#1
|
|||
|
|||
![]()
Assuming I have the following text:
Code:
Hello, "BOOKMARK_START" What are you doing 'BOOKMARK_END" Call me Code:
Hello, Call me Code:
Dim pRange Dim dRange Dim myrange pRange = ActiveDocument.Bookmarks("BOOKMARK_START").Range.Start dRange = ActiveDocument.Bookmarks("BOOKMARK_END").Range.End Set myrange = ActiveDocument.Range(Start:=pRange, End:=dRange) myrange.Cut Code:
Hello, BOOKMARK_START / BOOKMARK_END Call me How can I get round this? |
#2
|
||||
|
||||
![]()
Using Bookmarks is quite clumsy because you have little control on where those bookmarks start/end and the 'end' may be in front of the 'start'. Once you have removed the intervening content you will find it difficult to prise the two locations apart again.
A simpler way of defining a location for content is to use a Content Control and write to that. Code:
ActiveDocument.SelectContentControlsByTitle("Info")(1).Range.Text = "Hi Mum"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
![]() Quote:
Code:
Sub Macro1 FillCC "MyCCTitle", ChrW(8203), True End Sub Code:
Public Sub FillCC(strCCTitle As String, strValue As String, bLock As Boolean) 'Graham Mayor - https://www.gmayor.com - Last updated - 03 Sep 2021 Dim oCC As ContentControl On Error GoTo lbl_Exit For Each oCC In ActiveDocument.ContentControls With oCC If .Title = strCCTitle Then .LockContents = False .Range.Text = strValue .LockContentControl = True .LockContents = bLock Exit For End If End With Next oCC lbl_Exit: Set oCC = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
![]()
Thanks for the suggestions.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
RedZed1100 | Word VBA | 11 | 08-26-2020 04:15 PM |
Replacing text held in all bookmarks | THH4929 | Word VBA | 6 | 06-02-2018 04:29 AM |
Delete Selected Bookmarks | sks27 | Word VBA | 3 | 06-03-2016 02:05 AM |
![]() |
brent chadwick | Word VBA | 3 | 12-24-2015 01:40 PM |
![]() |
PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |