在我的研究中,我遇到了两种可能性,使用Chr(10)或Chr(13)将回车符插入VBA宏的标题中.我甚至看过Allen Wyatt在excel.tips.com上发布的代码似乎完全正是我正在尝试的内容,但是他断言它起作用的地方,我还没有看到成功.
这是我试图执行的基本代码:
With ActiveSheet.PageSetup
.CenterHeader = "&F" & Chr(10) & "&A"
End With
Run Code Online (Sandbox Code Playgroud)
我正在做其他格式化,但一切都成功了.此行仅在标题("&F")中生成文件名,但在第二行上没有返回且没有标签名称.它也不会失败; 它只是继续通过这条线.
这个宏最初由我在Excel 2010中记录,然后我通过额外的页面格式自动化进行了扩充.我仍然在Excel 2010下运行它,它在这个特定的行上从未正常工作.有没有人知道这里可能会发生什么?
编辑:这是原始宏录制和我的编辑的完整代码.
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = ""
.LeftHeader = ""
.CenterHeader = "&F" & vbCrLf & "&A"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = "Printed &D"
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = …Run Code Online (Sandbox Code Playgroud)