Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
PmcPowell PmcPowell is offline
Junior Member
 
Posts: 0
Angry Bookmarks Created by macro show whole cell when used by Ref Fields.

Hi - This is my first post in this forum. 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, 70 views)
 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bookmarks OLE_LINKs - What Are They and Why Are They Created pom15595 Microsoft Word Help 4 April 27th 10 11:05 AM
Bookmarks OLE_LINKs - What Are They and Why Are They Created pom15595 Microsoft Word Help 0 April 23rd 10 07:45 AM
Randomly Created Bookmarks Idaho Word Man Microsoft Word Help 3 October 9th 08 02:55 PM
mail merge- the fields that i created to not show in the word document. Stephen Mailmerge 1 June 2nd 08 01:20 AM
Bookmarks, TOC fields, PageRef fields disappear after print previe sjnet Microsoft Word Help 1 August 2nd 06 08:49 AM


All times are GMT +1. The time now is 08:54 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"