Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2021, 10:58 AM
nyconfidential nyconfidential is offline Add a bookmark at a certain line/column Windows 10 Add a bookmark at a certain line/column Office 2019
Novice
Add a bookmark at a certain line/column
 
Join Date: Nov 2021
Posts: 4
nyconfidential is on a distinguished road
Default Add a bookmark at a certain line/column


Hi all - I have a bunch of documents that I need to add the same three bookmarks to ad the exact same place (lets say, lines 3, 4 and 5 at column 20). Is there a simple way to add the bookmark at the specified locations? I've tried playing with the range property but I cannot seem to get it to work. Thanks for your help.
Reply With Quote
  #2  
Old 11-03-2021, 02:19 PM
Guessed's Avatar
Guessed Guessed is offline Add a bookmark at a certain line/column Windows 10 Add a bookmark at a certain line/column Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
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

You need to define the locations based on how Word refers to its own structure

Word doesn't really work in terms of 'lines' since that is fluid based on a huge number of factors. 'Paragraphs' is the usual reference point.

Columns could be either talking about a page layout column or a table column. Either way, 20 is an extraordinarily large number for a real world situation. Page layout columns is another ill-defined term like 'lines' since it is also fluid. However table columns are easy to work with but you need to specify which table you are talking about.

If you want code that will work, you should post a sample document and identify what are the triggers that uniquely identify your chosen locations eg always the 3rd table, 3rd row, 20th column, 1st paragraph.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-04-2021, 09:53 AM
nyconfidential nyconfidential is offline Add a bookmark at a certain line/column Windows 10 Add a bookmark at a certain line/column Office 2019
Novice
Add a bookmark at a certain line/column
 
Join Date: Nov 2021
Posts: 4
nyconfidential is on a distinguished road
Default

Thanks for your in depth response! See attached screenshot - these are pre-built Word documents, I want to put bookmarks next to "Effective Date", "Policy Number" and "Issued to" - which are always on line 7, 8 and 9 in all of these Word documents. I have some VBA code in Excel that looks for these bookmarks and inserts data from Excel into Word based on the bookmark names. (I've inserted the bookmarks manually into a Word document and the code has worked, I just thought I could save some time by creating these bookmarks in the 100+ Word documents programmatically rather than creating them in each individual Word file). Thank you!

Quote:
Originally Posted by Guessed View Post
You need to define the locations based on how Word refers to its own structure

Word doesn't really work in terms of 'lines' since that is fluid based on a huge number of factors. 'Paragraphs' is the usual reference point.

Columns could be either talking about a page layout column or a table column. Either way, 20 is an extraordinarily large number for a real world situation. Page layout columns is another ill-defined term like 'lines' since it is also fluid. However table columns are easy to work with but you need to specify which table you are talking about.

If you want code that will work, you should post a sample document and identify what are the triggers that uniquely identify your chosen locations eg always the 3rd table, 3rd row, 20th column, 1st paragraph.
Attached Images
File Type: png sample2.PNG (33.9 KB, 14 views)
Reply With Quote
  #4  
Old 11-04-2021, 03:39 PM
Guessed's Avatar
Guessed Guessed is offline Add a bookmark at a certain line/column Windows 10 Add a bookmark at a certain line/column Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
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

Firstly, I will say I'm not a fan of using bookmarks for a job like this because populating the text inside the bookmark is problematic. Instead, I would recommend you add Content Controls where you want to populate this content.

Secondly, I wouldn't bother with pre-setting the locations in your documents since that seems like an additional step which could simply be part of the Excel macro.

This code is how I would do it for a single document and it could be adapted to sit in your Excel code.
Code:
Sub PopItIn()
  FillCC sCCtitle:="Effective Date", sValue:="my date", sFind:="Effective Date: "
  FillCC sCCtitle:="Policy Number", sValue:="123456", sFind:="Policy Number: "
  FillCC sCCtitle:="Issued To", sValue:="Joe Dirt", sFind:="Issued To: "
End Sub

Function FillCC(sCCtitle As String, sValue As String, sFind As String, Optional aDoc As Document) As ContentControl
  Dim aCC As ContentControl, aRng As Range
  If aDoc Is Nothing Then Set aDoc = ActiveDocument
  If aDoc.SelectContentControlsByTitle(sCCtitle).Count = 0 Then
    Set aRng = aDoc.Range
    With aRng.Find
      .ClearFormatting
      .Text = sFind
      If .Execute Then
        aRng.Collapse Direction:=wdCollapseEnd
        Set aCC = aDoc.ContentControls.Add(Type:=wdContentControlText, Range:=aRng)
        aCC.Title = sCCtitle
      Else
        Debug.Print "Neither Content Control nor Anchor text: " & sFind
        Exit Function
      End If
    End With
  Else
    Set aCC = aDoc.SelectContentControlsByTitle(sCCtitle)(1)
  End If
  aCC.Range.Text = sValue
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-05-2021, 08:39 AM
nyconfidential nyconfidential is offline Add a bookmark at a certain line/column Windows 10 Add a bookmark at a certain line/column Office 2019
Novice
Add a bookmark at a certain line/column
 
Join Date: Nov 2021
Posts: 4
nyconfidential is on a distinguished road
Default

Thank you so much!
Reply With Quote
Reply

Tags
bookmarks



Similar Threads
Thread Thread Starter Forum Replies Last Post
REf Fields show Bookmark whole cell when Bookmark is created by code. pmcpowell Word VBA 2 11-16-2019 07:05 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
Add a bookmark at a certain line/column Table column line moves joannechee2 Word Tables 7 03-17-2016 12:21 AM
Add a bookmark at a certain line/column Delete Line of Bookmark if the Text is Empty ljg713 Word VBA 1 12-21-2015 04:27 PM
Multi Line Bookmark streng Word 3 07-13-2009 07:54 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:25 AM.


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