gpt4 book ai didi

vba - Excel宏插入回车符

转载 作者:行者123 更新时间:2023-12-02 07:42:50 24 4
gpt4 key购买 nike

在我的研究中,我遇到了两种将回车符插入到 VBA 宏 header 中的可能性:使用 Chr(10) 或 Chr(13)。我什至看到 Allen Wyatt 在 excel.tips.com 发布的代码这似乎正是我正在尝试的,但在他声称它有效的地方,我还没有看到成功。

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

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

我正在做其他格式化,但一切都成功了。该行仅在 header (“&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

最佳答案

同意 Patrick H 的观点。此代码有效...

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

关于vba - Excel宏插入回车符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46477004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com