【问题标题】:Excel VBA to print the date and page number in the header and footerExcel VBA 在页眉和页脚中打印日期和页码
【发布时间】:2011-05-05 22:51:08
【问题描述】:

每当我的页面在左上角打印要打印的日期和在左下角打印页码时,我都希望这样。

如何在 excel 中使用 head 命令来完成。

head = "日期值"

Foot = "页码"

我知道还有其他方法可以做到这一点,但是我被要求专门使用这些功能来做到这一点。

【问题讨论】:

  • 我可能在编辑您编写的 vb 脚本时出错了。您究竟是如何访问/实施此打印的?

标签: excel vba printing pagination


【解决方案1】:
With ActiveSheet.PageSetup
  .LeftHeader = Format(Now(), "dd/mm/yy")
  .LeftFooter = "&P"
End With

【讨论】:

  • 看看我不应该使用leftheader
  • 我必须用头和脚这是我的主要问题
  • @Tom,我知道没有称为 head 和 foot 的功能,所以除非您的公司有自定义功能,否则我认为这就是他们的意思。 Excel 帮助中没有“头”或“脚”。
  • 这里是完整的背景故事,我们公司说页面打印太慢并联系了东芝。东芝说用head而不是.leftheader,我工作了一整天,但是head就是不工作,我必须使用它。
  • @FreeSoftwareServers 哇,这么多年都没人发现,应该是“&”,现在编辑。
【解决方案2】:
With ActiveSheet.PageSetup
  .LeftHeader = Format(Now(), "dddd, mmmm dd, yyyy")                                     ' Saturday, July 13, 2019
  .LeftFooter = "Page &P of &N"
End With

日期格式 --> https://powerspreadsheets.com/vba-format-date/#Format-Date-Using-VBA-Display-Several-Items-Of-The-Date

更新:

我曾经使用.LeftFooter = "Page " & ActiveSheet.Index & " of " & ActiveSheet.PageSetup.Pages.Count ' Page 1 of 2,但结果不一致,我发现使用.LeftFooter = "Page &P of &N"更好

更多&Foo例子请看这里 --> https://docs.microsoft.com/en-us/office/vba/excel/concepts/workbooks-and-worksheets/formatting-and-vba-codes-for-headers-and-footers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-01
    • 2011-11-01
    • 2020-02-06
    • 1970-01-01
    • 2022-09-23
    • 2020-07-29
    • 2011-11-08
    • 1970-01-01
    相关资源
    最近更新 更多