Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2021, 01:25 AM
frreubi frreubi is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2013
Novice
inserting a custom property field in a bookmark
 
Join Date: Apr 2021
Location: Laag-Soeren, The Netherlands
Posts: 4
frreubi is on a distinguished road
Lightbulb inserting a custom property field in a bookmark


I want to insert some text, a custom property field and some other text in an existing bookmark.

Can anyone give me an example how to solve this
Reply With Quote
  #2  
Old 04-29-2021, 04:01 AM
Guessed's Avatar
Guessed Guessed is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,324
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
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
  #3  
Old 04-29-2021, 01:38 PM
Charles Kenyon Charles Kenyon is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 7,372
Charles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud of
Default

Andrew showed you how to insert the DocProperty field for the built-in property "Title" and apply a bookmark to it. The same method would work with a custom document property.

I am unsure. When you talk about a "Custom Property" what, exactly, do you mean? Where and how is that property established?
Reply With Quote
  #4  
Old 05-01-2021, 04:57 AM
frreubi frreubi is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2013
Novice
inserting a custom property field in a bookmark
 
Join Date: Apr 2021
Location: Laag-Soeren, The Netherlands
Posts: 4
frreubi is on a distinguished road
Default Almost right...

@Guessed :
Your sollution extends the field with the text that is inserted after the field.

I tried if a range.collapse after range.end=field.result.end, but that gave the same result

any sugestions?
Reply With Quote
  #5  
Old 05-01-2021, 05:00 AM
frreubi frreubi is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2013
Novice
inserting a custom property field in a bookmark
 
Join Date: Apr 2021
Location: Laag-Soeren, The Netherlands
Posts: 4
frreubi is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Andrew showed you how to insert the DocProperty field for the built-in property "Title" and apply a bookmark to it. The same method would work with a custom document property.

I am unsure. When you talk about a "Custom Property" what, exactly, do you mean? Where and how is that property established?
this is what will work:
.Fields.Add(Range:=YourRange, Text:="DOCPROPERTY ""Your DocProperty""")
Reply With Quote
  #6  
Old 05-03-2021, 02:41 AM
frreubi frreubi is offline inserting a custom property field in a bookmark Windows 10 inserting a custom property field in a bookmark Office 2013
Novice
inserting a custom property field in a bookmark
 
Join Date: Apr 2021
Location: Laag-Soeren, The Netherlands
Posts: 4
frreubi is on a distinguished road
Default Problem solved

With a small change to the code it worked;

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 with spaces""")
aRng.InsertBefore "text in front"
aRng.End = aField.Result.End + 1
aRng.InsertAfter "text at end"
'aRng.Select
ActiveDocument.Bookmarks.Add Name:="aaa", Range:=aRng
End Sub
Reply With Quote
Reply

Tags
bookmark;content control, field

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting a custom property field in a bookmark Updating a custom property in the header JonFleming Word VBA 9 02-09-2016 05:22 AM
inserting a custom property field in a bookmark Update Custom Document Property in Template Byron Polk Word VBA 10 08-19-2014 07:19 AM
Custom Document Property Lost From Template bhaughey Word 8 03-05-2013 02:11 PM
Link Watermark to custom property kerend Word 0 04-08-2012 05:03 AM
inserting a custom property field in a bookmark QuickParts - custom document property untttt Word 2 06-09-2011 05:24 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:13 AM.


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