1、打开word文档,切换到“视图”标签-点击“宏”下拉箭头-点击“查看宏”。
2、在弹出的宏创建对话框,输入宏名字(可以是中文),然后点击右侧“创建”按钮。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210223104140653.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3B6NjQx,size_16,color_FFFFFF,t_70)
3、用所给的代码替换掉默认的内容: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210223104207108.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3B6NjQx,size_16,color_FFFFFF,t_70)
'**************************************
' 函数名: SelectAllTables
' 功 能:主要是把WORD文档中的所有表格选取上,以便单独对文档中的所有表格进行整体编辑。
'**************************************
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
4、粘贴完代码后,直接点击工具栏的运行按钮▶,此时文档中所有表格已经选中,关闭VBA编辑器。(再次运行宏的话,直接Alt+F8打开对话框,选中宏点击右侧“运行”) 5、在“表格工具”-设计-设置框线粗细-边框下拉菜单里点击“所有边框”,如果点击一次“所有边框”是取消掉所有表格的框线,接着再点一次“所有框线”即可。![在这里插入图片描述](https://img-blog.csdnimg.cn/20210223104254611.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3B6NjQx,size_16,color_FFFFFF,t_70)
|