selection.cells.count返回值不对?
我发现了。。。要是用户选择的单元格是整列,selection.cells.count 返回的值是正确的,
要是用户选择的单元格是随意不是连续的话,selection.cells.count 返回的值就是1
怎么这样呢?
还有,在Word里ALT+F11切换到VBA宏编辑环境下运行宏里的代码,和我在VB里运行相同的代码效果不一样,VB里直接报错,VBA里运行通过。
Dim oCell As Cell, ColArray() As Byte, RowArray() As Integer
Dim CellsCount As Integer, N As Integer, myTable As Table
Dim myCell As Cell, Sel As Selection
Dim Doc As Document
'Set Doc = Documents.Item(ActiveDocument.Name)
'Doc.Select
' ActiveDocument.Select
With Selection '//----这句VB报错selection为nothing
If .Information(wdWithInTable) Then
If .Type <> wdSelectionIP Then
CellsCount = .Cells.Count
ReDim ColArray(CellsCount - 1)
ReDim RowArray(CellsCount - 1)
For Each oCell In Selection.Cells
ColArray(N) = oCell.ColumnIndex
RowArray(N) = oCell.RowIndex
N = N + 1
Next
'此处可以添加遍历文档代码
With ActiveDocument
Set myTable = .Tables(2)
For N = 0 To CellsCount - 1
Set myCell = myTable.Cell(RowArray(N), ColArray(N))
Debug.Print .Range(myCell.Range.Start, myCell.Range.End - 1)
Next
End With
End If
End If
End With