Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-15-2019, 06:26 PM
pmcpowell pmcpowell is offline REf Fields show Bookmark whole cell when Bookmark is created by code. Windows 8 REf Fields show Bookmark whole cell when Bookmark is created by code. Office 2013
Novice
REf Fields show Bookmark whole cell when Bookmark is created by code.
 
Join Date: Feb 2016
Posts: 6
pmcpowell is on a distinguished road
Default REf Fields show Bookmark whole cell when Bookmark is created by code.

Hi - This is my first post in this forum for a few years. My other forum couldn't help me.
I created a macro which takes user inputted data from a Table Column and creates a Bookmark named in the adjacent column.
The macro works just fine after many attempts and being told that it couldn't be done. However, when the
Ref" fields in the body of the document are updated, they bring over the whole cell (in fact they create a Table with 1 row) at the insertion point. This of course messes up the document layout. If I go into each bookmark in the Table and Select inside the square brackets and insert the same bookmark, then the "Ref" field is fine. This of course defeats the object of having a macro.
You can see that the code references the .text property is used which should prevent this from happening.
The sample of the document is attached and the code is as follows:
---------------------------------------------------------------------------------
Sub Mcr_Set_Bookmarks()
'
' Mcr_Set_Bookmarks Macro
' This Macro Takes the User Inputted Data in the "Value" Column of the Data Sheet Table
' and allocates the Bookmark Name from the "Bookmark Name" Column
Dim BKMkName As Variant
Dim BkmkRange As Variant
Dim BkmkNameLength As Integer
Dim BkmkRangeLength As Integer
Dim rV As Integer
Dim Endrow As Integer
Dim StartRow As Integer
'---------------------------------------------------------------------
'On Error Resume Next
'StartRow = Val(InputBox("Enter First Row Number Which Contains Data", "First Row"))
StartRow = 2


Endrow = ActiveDocument.Tables(1).Rows.Count
rV = StartRow
'------------------------------------------------------------------ Loop Through all Values in Table and allocate Bookmarks
For rV = StartRow To Endrow
BkmkNameLength = Len(ActiveDocument.Tables(1).Cell(rV, 4).Range) - 2
BkmkRangeLength = Len(ActiveDocument.Tables(1).Cell(rV, 3).Range) - 2
BKMkName = Left(ActiveDocument.Tables(1).Cell(rV, 4).Range, BkmkNameLength)
Debug.Print BKMkName
BkmkRange = Left(ActiveDocument.Tables(1).Cell(rV, 3).Range, BkmkRangeLength)
ActiveDocument.Tables(1).Cell(rV, 3).Select
BkmkRange = Left(Selection.Range.Text, BkmkRangeLength)
'Debug.Print BkmkRange()
ActiveDocument.Bookmarks.Add Range:=ActiveDocument.Tables(1).Cell(rV, 3), Name:=BKMkName
Next rV

End Sub
-----------------------------------------------------------------------------------
The attached document contains a snip which shows what I mean with the whole cell appearing at the insertion point.

Any help would be greatly appreciated as I am at my wits end.
Thanks,
Peter
Attached Files
File Type: zip Automated_Sttements_Working_v_4.0.zip (77.2 KB, 9 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I code bookmark globally for different template? Yong Xiang Word VBA 17 02-06-2019 01:09 PM
REf Fields show Bookmark whole cell when Bookmark is created by code. Field Code: Show a value only if bookmark is not empty Cosmo Word 7 08-24-2018 01:46 PM
Bookmark will not show/hide based on CC Checkbox lord_kaiser Word VBA 1 04-17-2018 01:19 AM
REf Fields show Bookmark whole cell when Bookmark is created by code. Bookmark - add two merge fields dfin Word VBA 5 09-06-2016 10:08 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:08 PM.


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