word如何修改页边距/纸张纵向/装定线等vba代码

VBAword

1个回答

写回答

赫ai海

2024-09-23 23:17

+ 关注

word
word

下面的WAPP是事先定义的word文档工程变量。

以下代码为通过VBA代码来实现页面的页边距、纸张纵向、装定线、页眉页静等。

复制代码

VBA
VBA

代码如下:

WApp.ActiveDocument.PageSetup.LineNumbering.Active =0;//行编号

WApp.ActiveDocument.PageSetup.Orientation =Microsoft.Office.Interop.word.WdOrientation.wdOrientPortrAIt;//页面方向

WApp.ActiveDocument.PageSetup.TopMargin =WApp.CentimetersToPoints(float.Parse(2.54));//上页边距

WApp.ActiveDocument.PageSetup.BottomMargin = WApp.CentimetersToPoints(float.Parse(2.54));//下页边距

WApp.ActiveDocument.PageSetup.LeftMargin = WApp.CentimetersToPoints(float.Parse(3.17));//左页边距

WApp.ActiveDocument.PageSetup.RightMargin = WApp.CentimetersToPoints(float.Parse(3.17));//右页边距

WApp.ActiveDocument.PageSetup.Gutter = WApp.CentimetersToPoints(float.Parse(0));//装订线位置

WApp.ActiveDocument.PageSetup.HeaderDistance = WApp.CentimetersToPoints(float.Parse(1.5));//页眉

WApp.ActiveDocument.PageSetup.FooterDistance = WApp.CentimetersToPoints(float.Parse(1.75));//页脚

WApp.ActiveDocument.PageSetup.PageWidth = WApp.CentimetersToPoints(float.Parse(21));//纸张宽度

WApp.ActiveDocument.PageSetup.PageHeight = WApp.CentimetersToPoints(float.Parse(29.7));//纸张高度

WApp.ActiveDocument.PageSetup.FirstPageTray = Microsoft.Office.Interop.word.WdPaperTray.wdPrinterDefaultBin;//纸张来源

WApp.ActiveDocument.PageSetup.OtherPagesTray = Microsoft.Office.Interop.word.WdPaperTray.wdPrinterDefaultBin;//纸张来源

WApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.word.WdSectionStart.wdSectionNewPage;//节的起始位置:新建页

WApp.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = 0;//页眉页脚-奇偶页不同

WApp.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0;//页眉页脚-首页不同

WApp.ActiveDocument.PageSetup.VerticalAlignment = Microsoft.Office.Interop.word.WdVerticalAlignment.wdAlignVerticalTop;//页面垂直对齐方式

WApp.ActiveDocument.PageSetup.SuppressEndnotes =0;//不隐藏尾注

WApp.ActiveDocument.PageSetup.MirrorMargins = 0;//不设置首页的内外边距

WApp.ActiveDocument.PageSetup.TwoPagesOnOne = false;//不双面打印

WApp.ActiveDocument.PageSetup.BookFoldPrinting =false;//不设置手动双面正面打印

WApp.ActiveDocument.PageSetup.BookFoldRevPrinting =false;//不设置手动双面背面打印

WApp.ActiveDocument.PageSetup.BookFoldPrintingSheets = 1;//打印默认份数

WApp.ActiveDocument.PageSetup.GutterPos = Microsoft.Office.Interop.word.WdGutterStyle.wdGutterPosLeft;//装订线位于左侧

WApp.ActiveDocument.PageSetup.LinesPage = 40;//默认页行数量

WApp.ActiveDocument.PageSetup.LayoutMode = Microsoft.Office.Interop.word.WdLayoutMode.wdLayoutModeLineGrid;//版式模式为只指定行网格

举报有用(17分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号