如何在VB里设置Excel文件的页眉或页脚的字

如何在VB里设置Excel文件的页眉或页脚的字,第1张

1

2

3

4

5

6

7

8

9

10

11

12

Sub test()

Application.PrintCommunication = False

With ActiveSheet.PageSetup

.LeftHeader = ""'页眉设置为:空

.CenterHeader = "&F"'页眉中设置为:文件名

.RightHeader = "" '页眉右设置为:空

.LeftFooter = "&B 机密 &B" '页脚左设置为:加粗的 机密两个字

.CenterFooter = "&D"'页脚中设置为:当前日期

.RightFooter = " 第 &P 页" '页脚右设置为:页码

End With

Application.PrintCommunication = True

End Sub

With WordDoc.ActiveWindow

If .View.SplitSpecial <> wdPaneNone Then

.Panes(2).Close

End If

If .ActivePane.View.Type = wdNormalView Or .ActivePane.View.Type = wdOutlineView Or .ActivePane.View.Type = wdMasterView Then

.ActivePane.View.Type = wdPageView

End If

.ActivePane.View.SeekView = wdSeekCurrentPageHeader

End With

With WordSel

.Font.Name = "楷体_GB2312"

.Font.Bold = True

.ParagraphFormat.Alignment = wdAlignParagraphRight

.TypeText Text:="这里是页眉!"

'这里是Logo图片

Dim LogoFile As String

LogoFile = Path.App & "Logo.BMP"

On Error Resume Next

Kill LogoFile

On Error GoTo 0

SavePicture imgMyLogo.Picture, LogoFile

WordApp.ActiveDocument.Shapes.AddPicture Anchor:=.Range, FileName:=LogoFile, LinkToFile:=False, SaveWithDocument:=True

Kill LogoFile

.MoveDown Unit:=wdLine, Count:=1

.Font.Bold = True

.Font.Name = "楷体_GB2312"

.ParagraphFormat.Alignment = wdAlignParagraphCenter

.TypeText Text:="这里是页脚"

WordDoc.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

End With

可以在页面设置对话框中改变页眉和页脚的大小。

1、单击页面布局选项卡右下角如图所示的按钮;

2、d出页面设置对话框,选择版式选项卡,在页眉、页脚的输入框中输入所需要的数值即可,如图所示。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11426719.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存