View Single Post
 
Old 04-29-2021, 04:01 AM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm sure there will be a more elegant way to do this but this is my first attempt
Code:
Sub DemoReplaceBookmark()
  Dim aRng As Range, aField As Field
  Set aRng = ActiveDocument.Bookmarks("aaa").Range
  Set aField = ActiveDocument.Fields.Add(Range:=aRng, Text:="DocProperty Title")
  aRng.InsertBefore "text in front"
  aRng.End = aField.Result.End
  aRng.InsertAfter "text at end"
  'aRng.Select
  ActiveDocument.Bookmarks.Add Name:="aaa", Range:=aRng
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote