在Word中用cell来表示单元格。要选择表格中的区域B3:D6的话,那么应该是如下代码:
Sub 选择表格中的区域()
With ActiveDocument
.Range(.Tables(1).Cell(3, 2).Range.Start, .Tables(1).Cell(6, 4).Range.End).Select
End With
End Sub
Sub SelectAllTables()
Dim tempTable As Table
Application.ScreenUpdating = False
'判断文档是否被保护
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
MsgBox "文档已保护,此时不能选中多个表格!"
Exit Sub
End If
'删除所有可编辑的区域
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
'添加可编辑区域
For Each tempTable In ActiveDocument.Tables
tempTable.Range.Editors.Add wdEditorEveryone
Next
'选中所有可编辑区域
ActiveDocument.SelectAllEditableRanges wdEditorEveryone
'删除所有可编辑的区域
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
Application.ScreenUpdating = True
End Sub
ActiveDocument.Tables
这个Tables集合代表当前文档中所有的表格,但是集合貌似不提供select方法,
如果你有后续操作,可以遍历这个集合中所有的表格单个进行处理,效果还是一样的
Sub konggs()
Dim mytable As Table
Application.ScreenUpdating = False
For Each mytable In ActiveDocument.Tables
mytable.Range.Editors.Add wdEditorEveryone
Next
ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
Application.ScreenUpdating = True
End Sub