用VBA批量处理word 中的表格:将表格内容调整为上下,左右居中,表格设置为根据窗口调整表格
SubBatchChangeTableAndPageMargins()OnErrorResumeNextConststrRootPath="D:\Temp\Docs\Ta...
Sub BatchChangeTableAndPageMargins()
On Error Resume Next
Const strRootPath = "D:\Temp\Docs\Tables" ' 存放所有需要调整的文件的目录
Dim arrDocFiles As New Collection
Dim fso, oFolder, oFile
Dim oDoc As Document
Dim oTable As Table
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
For Each oFile In oFolder.Files
Set oDoc = Documents.Open(oFile.Path)
oDoc.PageSetup.TopMargin = CentimetersToPoints(3) ' 天头
oDoc.PageSetup.BottomMargin = CentimetersToPoints(2.8) ' 地脚
oDoc.PageSetup.LeftMargin = CentimetersToPoints(2.5) ' 切口
oDoc.PageSetup.RightMargin = CentimetersToPoints(2) ' 订口
For Each oTable In oDoc.Tables
oTable.Range.Font.Name = "黑体" ' 改变表格字体为“黑体”
oTable.Range.Font.Size = 10.5 ' 改变表格字号为12磅
Next
oDoc.Close True
Next
Set oTable = Nothing
Set oDoc = Nothing
MsgBox "完成!"
End Sub
是要填上哪句话? 展开
On Error Resume Next
Const strRootPath = "D:\Temp\Docs\Tables" ' 存放所有需要调整的文件的目录
Dim arrDocFiles As New Collection
Dim fso, oFolder, oFile
Dim oDoc As Document
Dim oTable As Table
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(strRootPath)
For Each oFile In oFolder.Files
Set oDoc = Documents.Open(oFile.Path)
oDoc.PageSetup.TopMargin = CentimetersToPoints(3) ' 天头
oDoc.PageSetup.BottomMargin = CentimetersToPoints(2.8) ' 地脚
oDoc.PageSetup.LeftMargin = CentimetersToPoints(2.5) ' 切口
oDoc.PageSetup.RightMargin = CentimetersToPoints(2) ' 订口
For Each oTable In oDoc.Tables
oTable.Range.Font.Name = "黑体" ' 改变表格字体为“黑体”
oTable.Range.Font.Size = 10.5 ' 改变表格字号为12磅
Next
oDoc.Close True
Next
Set oTable = Nothing
Set oDoc = Nothing
MsgBox "完成!"
End Sub
是要填上哪句话? 展开
1个回答
展开全部
你把
For Each oTable In oDoc.Tables
oTable.Range.Font.Name = "黑体" ' 改变表格字体为“黑体”
oTable.Range.Font.Size = 10.5 ' 改变表格字号为12磅
Next
改为:
For Each oTable In oDoc.Tables
oTable.AutoFitBehavior (wdAutoFitWindow) '根据窗口调整内容
oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中
oTable.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter '垂直居中
Next
For Each oTable In oDoc.Tables
oTable.Range.Font.Name = "黑体" ' 改变表格字体为“黑体”
oTable.Range.Font.Size = 10.5 ' 改变表格字号为12磅
Next
改为:
For Each oTable In oDoc.Tables
oTable.AutoFitBehavior (wdAutoFitWindow) '根据窗口调整内容
oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中
oTable.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter '垂直居中
Next
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询