S
Stephen English
Hi
I am using Cindy Meister's code from MSDN (below) for selecting a range of
cells in a table.
I am doing this from an Access 2003 module with all objects dimensioned as
Word objects (Word.table, Word.selection etc).
sel = SelectCells(tblClub, 1, 2, 10, 2)
When it returns from the function, it fails because it it says sel is set to
nothing.
However, when I step through the function it seems to be setting it and sel
shows as "black dot".
Any ideas please?
Regards
Stephen English
Set tblClub = docClub.Tables(1)
With tblClub
.Columns(1).PreferredWidthType = wdPreferredWidthPoints
.Columns(1).PreferredWidth = CentimetersToPoints(9.03)
.Columns(2).PreferredWidthType = wdPreferredWidthPoints
.Columns(2).PreferredWidth = CentimetersToPoints(3.5)
sel = SelectCells(tblClub, 1, 2, 10, 2)
If Not sel Is Nothing Then
sel.Cells.Merge
End If
End With
Function SelectCells(ByRef tbl As Word.Table, _
rowStart As Integer, ByVal colStart As Integer, _
ByVal rowEnd As Integer, ByVal colEnd As Integer) _
As Word.Selection
Dim sel As Word.Selection
Dim i As Long
Dim nrRows As Long
Dim nrCols As Long
Set sel = Nothing
nrRows = tbl.Rows.Count
nrCols = tbl.Columns.Count
'Make sure the start cell exists in the table
If rowStart > nrRows Then Exit Function
If colStart > nrCols Then Exit Function
'Make sure the end point exists in the table
'If it does not, set the last row/column as end points
If rowEnd >= nrRows Then rowEnd = nrRows - rowStart + 1
If colEnd >= nrCols Then colEnd = nrCols - colStart + 1
'Select the start cell
tbl.Cell(rowStart, colStart).Select
Set sel = Selection
'Make sure the selection will extend
sel.ExtendMode = True
'First select the start cell
sel.Expand Unit:=wdCell
'Now extend across the columns
'-1 because first row and col are already selected
sel.MoveRight Unit:=wdCharacter, Count:=colEnd - 1, Extend:=True
'And now extend down the rows
sel.MoveDown Unit:=wdLine, Count:=rowEnd - 1, Extend:=True
Set SelectCells = sel
End Function
I am using Cindy Meister's code from MSDN (below) for selecting a range of
cells in a table.
I am doing this from an Access 2003 module with all objects dimensioned as
Word objects (Word.table, Word.selection etc).
sel = SelectCells(tblClub, 1, 2, 10, 2)
When it returns from the function, it fails because it it says sel is set to
nothing.
However, when I step through the function it seems to be setting it and sel
shows as "black dot".
Any ideas please?
Regards
Stephen English
Set tblClub = docClub.Tables(1)
With tblClub
.Columns(1).PreferredWidthType = wdPreferredWidthPoints
.Columns(1).PreferredWidth = CentimetersToPoints(9.03)
.Columns(2).PreferredWidthType = wdPreferredWidthPoints
.Columns(2).PreferredWidth = CentimetersToPoints(3.5)
sel = SelectCells(tblClub, 1, 2, 10, 2)
If Not sel Is Nothing Then
sel.Cells.Merge
End If
End With
Function SelectCells(ByRef tbl As Word.Table, _
rowStart As Integer, ByVal colStart As Integer, _
ByVal rowEnd As Integer, ByVal colEnd As Integer) _
As Word.Selection
Dim sel As Word.Selection
Dim i As Long
Dim nrRows As Long
Dim nrCols As Long
Set sel = Nothing
nrRows = tbl.Rows.Count
nrCols = tbl.Columns.Count
'Make sure the start cell exists in the table
If rowStart > nrRows Then Exit Function
If colStart > nrCols Then Exit Function
'Make sure the end point exists in the table
'If it does not, set the last row/column as end points
If rowEnd >= nrRows Then rowEnd = nrRows - rowStart + 1
If colEnd >= nrCols Then colEnd = nrCols - colStart + 1
'Select the start cell
tbl.Cell(rowStart, colStart).Select
Set sel = Selection
'Make sure the selection will extend
sel.ExtendMode = True
'First select the start cell
sel.Expand Unit:=wdCell
'Now extend across the columns
'-1 because first row and col are already selected
sel.MoveRight Unit:=wdCharacter, Count:=colEnd - 1, Extend:=True
'And now extend down the rows
sel.MoveDown Unit:=wdLine, Count:=rowEnd - 1, Extend:=True
Set SelectCells = sel
End Function