Word VBA help?
#1
I am trying to copy a formfield from row 2 of a table down the whole column and then name it appropriately with the following code. The code fails at the rng.FormFields(1).Name = nkh
line.
Any ideas?
Dim rowCount As Integer
Dim colCount As Integer
Dim t As Table
Dim bmName As String
Dim rng As Range
Dim nkh As String
Set t = ActiveDocument.Tables(1)
For colCount = 1 To t.Columns.Count
Set rng = t.Cell(2, colCount).Range
rng.MoveEnd Unit:=wdCharacter, Count:=-1
If rng.FormFields.Count >= 1 Then
'There is a formfield to copy and rename
rng.FormFields(1).Copy
bmName = rng.FormFields(1).Name
For rowCount = 3 To t.Rows.Count
Set rng = t.Cell(rowCount, colCount).Range
rng.MoveEnd Unit:=wdCharacter, Count:=-1
rng.Paste
nkh = "Tbl" & bmName & rowCount
MsgBox (nkh)
If ActiveDocument.Bookmarks.Exists(nkh) Then MsgBox ("HELP")
rng.FormFields(1).Name = nkh
Next
End If
Next
End Sub
line.
Any ideas?
Dim rowCount As Integer
Dim colCount As Integer
Dim t As Table
Dim bmName As String
Dim rng As Range
Dim nkh As String
Set t = ActiveDocument.Tables(1)
For colCount = 1 To t.Columns.Count
Set rng = t.Cell(2, colCount).Range
rng.MoveEnd Unit:=wdCharacter, Count:=-1
If rng.FormFields.Count >= 1 Then
'There is a formfield to copy and rename
rng.FormFields(1).Copy
bmName = rng.FormFields(1).Name
For rowCount = 3 To t.Rows.Count
Set rng = t.Cell(rowCount, colCount).Range
rng.MoveEnd Unit:=wdCharacter, Count:=-1
rng.Paste
nkh = "Tbl" & bmName & rowCount
MsgBox (nkh)
If ActiveDocument.Bookmarks.Exists(nkh) Then MsgBox ("HELP")
rng.FormFields(1).Name = nkh
Next
End If
Next
End Sub
Thread
Thread Starter
Forum
Replies
Last Post
johnfelstead
ScoobyNet General
85
22 March 2001 12:02 PM
SDB
ScoobyNet General
2
12 January 2001 10:43 AM