- ·上一篇:excel双引号反了怎么调整
- ·下一篇:excel中保留整数怎么弄
excel怎么用vba设置页眉
1.Excel 如何用VBA设置页眉的字体
Sub test() Application.PrintCommunication = False With ActiveSheet.PageSetup .LeftHeader = "" '页眉左设置为:空 .CenterHeader = "&F" '页眉中设置为:文件名 .RightHeader = "" '页眉右设置为:空 .LeftFooter = "&B 机密 &B" '页脚左设置为:加粗的 机密两个字 .CenterFooter = "&D" '页脚中设置为:当前日期 .RightFooter = " 第 &P 页" '页脚右设置为:页码 End With Application.PrintCommunication = TrueEnd Sub。
2.excel 根据表格内容自动运行VBA设置的页眉
你可以用Workbook_SheetSelectionChange时间,即选择区域改变是执行,也就是其他单元格点下就行了~
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
With ActiveSheet.PageSetup
.RightHeader = "&""Arial""&10&A " & Cells(4, 4) & " Page &P/&N"
End With
End Sub
3.本人在用VBA进行打印程序设计,请问怎样利用VBA代码进行页眉、?
进行页面设置: a。
页眉: ExcelID。ActiveSheet。
PageSetup。CenterHeader := '报表演示 '; b。
页脚: ExcelID。ActiveSheet。
PageSetup。CenterFooter := '第&P页 '; c。
页眉到顶端边距2cm: ExcelID。ActiveSheet。
PageSetup。HeaderMargin := 2/0。
035; d。页脚到底端边距3cm: ExcelID。
ActiveSheet。PageSetup。
HeaderMargin := 3/0。035; e。
顶边距2cm: ExcelID。 ActiveSheet。
PageSetup。TopMargin := 2/0。
035; f。底边距2cm: ExcelID。
ActiveSheet。PageSetup。
BottomMargin := 2/0。 035; g。
左边距2cm: ExcelID。ActiveSheet。
PageSetup。LeftMargin := 2/0。
035; h。右边距2cm: ExcelID。
ActiveSheet。PageSetup。
RightMargin := 2/0。035; i。
页面水平居中: ExcelID。ActiveSheet。
PageSetup。CenterHorizontally := 2/0。
035; j。页面垂直居中: ExcelID。
ActiveSheet。PageSetup。
CenterVertically := 2/0。035; k。
打印单元格网线: ExcelID。 ActiveSheet。
PageSetup。PrintGridLines := True; 。
4.求EXCEL VBA 锁定页眉页脚代码
以下都是随便设的值,可根据自己的需要修改: Sub MyPageSetup() With ActiveSheet.PageSetup '页眉左设置为,空 .LeftHeader = "" '页眉中设置为,文件名 .CenterHeader = "&F" '页眉右设置为,空 .RightHeader = "" '左页脚内容为abc=abcabc,字体为10号(代码中&10) .LeftFooter = "&10 abc=abcabc " '设置右页脚,第多少页of总页数 .RightFooter = "Page &P of &N" '页脚中设置为,当前日期 .CenterFooter = "&D" '设置左右上下边线距 .LeftMargin = Application.InchesToPoints(0.19) .RightMargin = Application.InchesToPoints(0.31) .TopMargin = Application.InchesToPoints(0.35) .BottomMargin = Application.InchesToPoints(0.83) .HeaderMargin = Application.InchesToPoints(0.31) .FooterMargin = Application.InchesToPoints(0.19) '设置(排版方向,横或竖)) .Orientation = xlLandscape '设置打印标题行(以下是设第3行和第4行) .PrintTitleRows = "$3:$4" '选择打印纸张' .PaperSize = xlPaperA4 End WithEnd Sub。
