Excelmacros插入回车

在我的研究中,我遇到了两种使用Chr(10)或Chr(13)将回车插入VBAmacros中的头文件的可能性。 我甚至在excel.tips.com上看到了Allen Wyatt发布的代码,这个代码似乎完全是我正在尝试的,但是他声称它的工作原理,我还没有看到成功。

这是我正在尝试执行的基本代码:

With ActiveSheet.PageSetup .CenterHeader = "&F" & Chr(10) & "&A" End With 

还有其他格式我正在做,但一切都成功了。 该行只在标题(“&F”)中生成文件名,但在第二行没有返回和标签名称。 它也不失败; 它只是继续通过这条线。

这个macros最初是由我在Excel 2010中录制的,然后增加了页面格式的自动化。 我仍然在Excel 2010下运行它,它在这个特定的行上从来没有正确的工作。 有没有人知道什么可能在这里蒸发?

编辑:这是从原始macroslogging和我的编辑完整的代码。

 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 

同意Patrick H.此代码适用于…

 Sub header() With ActiveSheet.PageSetup .CenterHeader = "&F" & vbCrLf & "&A" End With End Sub