代码解释:
首先设置页边距,纵向页面为左2.52,上下右各2;横向页面为上2.54,左右下各50px;
然后设置图谱大小为高600px,宽409.99999999999994px
如果为横向页面需要在运行后手动调整图谱大小
对于S2附件2这一类图文都有的文件,代码设置高度小于20的图片不予调整,这样正文中的专属性图就不会被改动。
代码中的页边距和图谱大小数值均可以根据需要改动
Sub 调整图片()
Dim n
On Error Resume Next '忽略错误
For n = 1 To ActiveDocument.Sections.Count '文档有多少分节符
WithActiveDocument.Sections(n).PageSetup
'对每一节进行页面设置
'首先判断页面是横向还是纵向,分别设置页边距
If .Orientation = wdOrientPortrait Then '如果是纵向
.LineNumbering.Active = False
.TopMargin = CentimetersToPoints(2) '上边距50px
.BottomMargin = CentimetersToPoints(2) '下边距50px
.LeftMargin = CentimetersToPoints(2.54) '左边距63.5px
.RightMargin = CentimetersToPoints(2) '右边距50px
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5) '页眉37.5px
.FooterDistance = CentimetersToPoints(0.8) '页脚20px
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LinesPage = 44
.LayoutMode = wdLayoutModeLineGrid
Else
.TopMargin = CentimetersToPoints(2.54) '上边距63.5px
.BottomMargin = CentimetersToPoints(2) '下边距50px
.LeftMargin = CentimetersToPoints(2) '左边距50px
.RightMargin = CentimetersToPoints(2) '右边距50px
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5) '页眉37.5px
.FooterDistance = CentimetersToPoints(0.8) '页脚20px
End If
End With
Next n
'Word中的尺寸单位默认是cm(厘米),而25px等于28.35px(像素),由于代码中换算设置的单位是px(像素)。所以就用尺寸高度或宽度值乘像素值。即为:24*28.35;宽度换算方法与此相同。
For n = 1To ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(n).Height > 20 * 28.35 Then '不对专属性的小图片进行改变
ActiveDocument.InlineShapes(n).Height = 24 * 28.35 '设置图片高度为 600px
ActiveDocument.InlineShapes(n).Width = 16.4 * 28.35 '设置图片宽度 409.99999999999994px
End If
Next n
End Sub
首先设置页边距,纵向页面为左2.52,上下右各2;横向页面为上2.54,左右下各50px;
然后设置图谱大小为高600px,宽409.99999999999994px
如果为横向页面需要在运行后手动调整图谱大小
对于S2附件2这一类图文都有的文件,代码设置高度小于20的图片不予调整,这样正文中的专属性图就不会被改动。
代码中的页边距和图谱大小数值均可以根据需要改动
Sub 调整图片()
Dim n
On Error Resume Next '忽略错误
For n = 1 To ActiveDocument.Sections.Count '文档有多少分节符
WithActiveDocument.Sections(n).PageSetup
'对每一节进行页面设置
'首先判断页面是横向还是纵向,分别设置页边距
If .Orientation = wdOrientPortrait Then '如果是纵向
.LineNumbering.Active = False
.TopMargin = CentimetersToPoints(2) '上边距50px
.BottomMargin = CentimetersToPoints(2) '下边距50px
.LeftMargin = CentimetersToPoints(2.54) '左边距63.5px
.RightMargin = CentimetersToPoints(2) '右边距50px
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5) '页眉37.5px
.FooterDistance = CentimetersToPoints(0.8) '页脚20px
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LinesPage = 44
.LayoutMode = wdLayoutModeLineGrid
Else
.TopMargin = CentimetersToPoints(2.54) '上边距63.5px
.BottomMargin = CentimetersToPoints(2) '下边距50px
.LeftMargin = CentimetersToPoints(2) '左边距50px
.RightMargin = CentimetersToPoints(2) '右边距50px
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5) '页眉37.5px
.FooterDistance = CentimetersToPoints(0.8) '页脚20px
End If
End With
Next n
'Word中的尺寸单位默认是cm(厘米),而25px等于28.35px(像素),由于代码中换算设置的单位是px(像素)。所以就用尺寸高度或宽度值乘像素值。即为:24*28.35;宽度换算方法与此相同。
For n = 1To ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(n).Height > 20 * 28.35 Then '不对专属性的小图片进行改变
ActiveDocument.InlineShapes(n).Height = 24 * 28.35 '设置图片高度为 600px
ActiveDocument.InlineShapes(n).Width = 16.4 * 28.35 '设置图片宽度 409.99999999999994px
End If
Next n
End Sub