Digilee
04-21-2011, 11:33 AM
Hi,
I am a firmware engineer trying to help the Tech Pubs guys out by automating register table creation for our Programmer's Reference documents. For the past three weeks I have been teaching myself VBA, which obviously is not enough because there are a lot of gaps in my knowledge.
All is going well until I try to add a page cross-reference field to my summary table. I can (and do) add a separate hyperlink in the next column, but I get a 4605 'Command not available' error when attempting to insert the field.
This is the code for building a single row in the summary table. I have attached an example file that shows a completed summary table (except for the page reference field), along with the tables that are used to create the summary table.
Any help would be greatly appreciated...
Regards,
Lee
Function SummaryTableEntry(bmIndex As Long, nRow As row) As Boolean
Dim offsetText As String
Dim tableOffsetText As String
Dim xTable As Table
Dim colonPos As Long
Dim i As Long
offsetText = Right(Trim(ActiveDocument.Bookmarks(bmIndex).Name), 4)
' Insert offset from bookmark name into offset column
nRow.Cells(1).Range.Text = offsetText
' Get the actual register name from the bookmarked table
Set xTable = ActiveDocument.Bookmarks(bmIndex).Range.Tables(1)
For i = 2 To xTable.Rows.count
' get the offset part of the Address/Offset field for this row
tableOffsetText = Main.fCellText(xTable.Rows(i).Cells(1).Range.Text)
colonPos = InStr(1, tableOffsetText, ":")
If colonPos <> 0 Then
tableOffsetText = Right(tableOffsetText, 4)
' If the bookmark offset value is the same as this row
' of the table offset, get the register name
If (InStr(1, offsetText, tableOffsetText) <> 0) Then
' Add register name to thrird column
nRow.Cells(3).Range.Text = Main.fCellText(xTable.Rows(i).Cells(2).Range.Text)
' Add hyperlink to table in third column
ActiveDocument.Hyperlinks.Add _
Anchor:=nRow.Cells(3).Range, _
Address:=ActiveDocument.FullName, _
SubAddress:=ActiveDocument.Bookmarks(bmIndex).Name, _
ScreenTip:=""
' Add Page reference hyperlink in second column
ActiveDocument.Range.Fields.Add _
Range:=nRow.Cells(2).Range, _
Type:=wdFieldPage, _
Text:="", _
PreserveFormatting:=True
Exit For
End If
Else
Exit For
End If
Next
SummaryTableEntry = True
End Function
I am a firmware engineer trying to help the Tech Pubs guys out by automating register table creation for our Programmer's Reference documents. For the past three weeks I have been teaching myself VBA, which obviously is not enough because there are a lot of gaps in my knowledge.
All is going well until I try to add a page cross-reference field to my summary table. I can (and do) add a separate hyperlink in the next column, but I get a 4605 'Command not available' error when attempting to insert the field.
This is the code for building a single row in the summary table. I have attached an example file that shows a completed summary table (except for the page reference field), along with the tables that are used to create the summary table.
Any help would be greatly appreciated...
Regards,
Lee
Function SummaryTableEntry(bmIndex As Long, nRow As row) As Boolean
Dim offsetText As String
Dim tableOffsetText As String
Dim xTable As Table
Dim colonPos As Long
Dim i As Long
offsetText = Right(Trim(ActiveDocument.Bookmarks(bmIndex).Name), 4)
' Insert offset from bookmark name into offset column
nRow.Cells(1).Range.Text = offsetText
' Get the actual register name from the bookmarked table
Set xTable = ActiveDocument.Bookmarks(bmIndex).Range.Tables(1)
For i = 2 To xTable.Rows.count
' get the offset part of the Address/Offset field for this row
tableOffsetText = Main.fCellText(xTable.Rows(i).Cells(1).Range.Text)
colonPos = InStr(1, tableOffsetText, ":")
If colonPos <> 0 Then
tableOffsetText = Right(tableOffsetText, 4)
' If the bookmark offset value is the same as this row
' of the table offset, get the register name
If (InStr(1, offsetText, tableOffsetText) <> 0) Then
' Add register name to thrird column
nRow.Cells(3).Range.Text = Main.fCellText(xTable.Rows(i).Cells(2).Range.Text)
' Add hyperlink to table in third column
ActiveDocument.Hyperlinks.Add _
Anchor:=nRow.Cells(3).Range, _
Address:=ActiveDocument.FullName, _
SubAddress:=ActiveDocument.Bookmarks(bmIndex).Name, _
ScreenTip:=""
' Add Page reference hyperlink in second column
ActiveDocument.Range.Fields.Add _
Range:=nRow.Cells(2).Range, _
Type:=wdFieldPage, _
Text:="", _
PreserveFormatting:=True
Exit For
End If
Else
Exit For
End If
Next
SummaryTableEntry = True
End Function