在我的研究中,我遇到了两种在VBA宏中插入回车符的可能性,使用Chr(10)或Chr(13)。我甚至看到过Allen Wyatt在excel.tips.com上发布的代码似乎正是我尝试做的事情,但他断言这个方法可行,而我还没有看到成功的例子。
以下是我尝试执行的基本代码:
以下是我尝试执行的基本代码:
With ActiveSheet.PageSetup
.CenterHeader = "&F" & Chr(10) & "&A"
End With
我正在进行其他格式化操作,但它们都成功了。这一行只在标题中产生文件名("&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 = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
"&F" & vbCrLf & "&A"
。 - iDevlop