G
Goody
I am using the code shown below to populate a table. I assign each page a
bookmark, return to the table, insert a cross reference to the bookmark,
delete the bookmark, go to the next page, and repeat the process. The
procedure keeps track of the row and column positions, and moves the
selection point back to the top of the table and two columns to the right
when the last row is reached. For some reason, when the selection is in
anything other than the first column, the InsertCrossReference command still
puts its reference in the first column. I am trying to work around this
"feature", but I need a way to address the contents of the
InsertCrossReference method. How do I accomplish this?
Alternatively, if anyone can explain why the cross reference is always
placed in the first column, I might be able to avoid the work around.
Thanks,
Goody
***************************
Sub Macro1()
Dim tblRevList As Table
Dim irowcount As Integer, icolcount As Integer
Dim irow As Long, icolumn As Long
Set tblRevList = ActiveDocument.Tables(2)
icolumn = 1
irow = 2
irowcount = tblRevList.Rows.Count - 1
icolcount = tblRevList.Columns.Count
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=1, Name:=""
For Each ipage In ActiveDocument.ActiveWindow.ActivePane.Pages
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="here"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With ' Set bookmark for reference.
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2, Name:=""
tblRevList.Cell(irow, icolumn).Range.InsertCrossReference _
ReferenceType:=wdRefTypeBookmark, ReferenceKind:=wdPageNumber, _
ReferenceItem:="here", InsertAsHyperlink:=False,
IncludePosition:=False, _
SeparateNumbers:=False, SeparatorString:=" "
Selection.GoTo What:=wdGoToBookmark, Name:="here" ' Return to
bookmark location.
ActiveDocument.Bookmarks("here").Delete ' Clear bookmark
Application.Browser.Target = wdBrowsePage ' Change to browse by page
Application.Browser.Next ' Move to top of next page
If irow = irowcount + 1 Then ' Is cell at the bottom of the table?
icolumn = icolumn + 2 ' If so, move two columns to the right
irow = 2 ' and back to the top of the table.
Else
irow = irow + 1 ' Otherwise, move to next row
End If
Next
End Sub
bookmark, return to the table, insert a cross reference to the bookmark,
delete the bookmark, go to the next page, and repeat the process. The
procedure keeps track of the row and column positions, and moves the
selection point back to the top of the table and two columns to the right
when the last row is reached. For some reason, when the selection is in
anything other than the first column, the InsertCrossReference command still
puts its reference in the first column. I am trying to work around this
"feature", but I need a way to address the contents of the
InsertCrossReference method. How do I accomplish this?
Alternatively, if anyone can explain why the cross reference is always
placed in the first column, I might be able to avoid the work around.
Thanks,
Goody
***************************
Sub Macro1()
Dim tblRevList As Table
Dim irowcount As Integer, icolcount As Integer
Dim irow As Long, icolumn As Long
Set tblRevList = ActiveDocument.Tables(2)
icolumn = 1
irow = 2
irowcount = tblRevList.Rows.Count - 1
icolcount = tblRevList.Columns.Count
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=1, Name:=""
For Each ipage In ActiveDocument.ActiveWindow.ActivePane.Pages
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="here"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With ' Set bookmark for reference.
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2, Name:=""
tblRevList.Cell(irow, icolumn).Range.InsertCrossReference _
ReferenceType:=wdRefTypeBookmark, ReferenceKind:=wdPageNumber, _
ReferenceItem:="here", InsertAsHyperlink:=False,
IncludePosition:=False, _
SeparateNumbers:=False, SeparatorString:=" "
Selection.GoTo What:=wdGoToBookmark, Name:="here" ' Return to
bookmark location.
ActiveDocument.Bookmarks("here").Delete ' Clear bookmark
Application.Browser.Target = wdBrowsePage ' Change to browse by page
Application.Browser.Next ' Move to top of next page
If irow = irowcount + 1 Then ' Is cell at the bottom of the table?
icolumn = icolumn + 2 ' If so, move two columns to the right
irow = 2 ' and back to the top of the table.
Else
irow = irow + 1 ' Otherwise, move to next row
End If
Next
End Sub