Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Bookmarks OLE_LINKs - What Are They and Why Are They Created | Microsoft Word Help | |||
Bookmarks OLE_LINKs - What Are They and Why Are They Created | Microsoft Word Help | |||
Randomly Created Bookmarks | Microsoft Word Help | |||
mail merge- the fields that i created to not show in the word document. | Mailmerge | |||
Bookmarks, TOC fields, PageRef fields disappear after print previe | Microsoft Word Help |