excel更改页眉页脚_带格式日期的Excel页脚

excel更改页眉页脚

It's Fancy Footer Friday! Check with your boss – maybe you can leave early to celebrate.

星期五是花式页脚! 与老板核实-也许您可以早点庆祝。

This week, I've been working on Excel printed reports, and one of my clients wanted some fancy features in the footer. There are built-in footer options in Excel, but my client wanted to pull information from the worksheet, and format the date, so we needed some footer programming.

本周,我一直在处理Excel打印的报表,我的一位客户希望在页脚中添加一些精美的功能。 Excel中有内置的页脚选项,但是我的客户想从工作表中提取信息并格式化日期,因此我们需要一些页脚编程。

将订单信息添加到页脚 (Add Order Information to Footer)

In this example, I've created an order sheet, and named the cells where the Order Date, Customer Name, and Order Number are entered.

在此示例中,我创建了一个订单表,并命名了在其中输入“订单日期”,“客户名称”和“订单号” 的单元格

ExcelFooterMacro01

运行Excel页脚宏 (Run the Excel Footer Macro)

Then, the SetFooter code, shown below, is pasted into a module in the workbook. When you run the SetFooter macro, it adds the customer name and order number in the left footer.

然后,将如下所示的SetFooter代码粘贴到工作簿中的模块中。 当您运行SetFooter宏时,它将在左侧页脚中添加客户名称和订单号。

The line break is created with the Chr(10) code.

换行符是使用Chr(10)代码创建的。

ExcelFooterMacro02

In the right footer, the order date appears, formatted as dd-mmm-yyyy.

在右页脚中,显示订购日期,格式为dd-mmm-yyyy。

ExcelFooterMacro03

Excel页脚示例代码 (Excel Footer Sample Code)

If you download the sample workbook, you'll see the code that is used to add the Order Date, Customer Name, and Order Number to the footer.

如果您下载示例工作簿,您将看到用于将订单日期,客户名称和订单号添加到页脚的代码。

excel footer macro code

修改代码 (Modify the Code)

Copy the code to your workbook, then modify the code, so it has the sheet name and range names used in your workbook.

将代码复制到工作簿中 ,然后修改代码,使其具有工作簿中使用的工作表名称和范围名称。

You'll have to change the following lines of code.

您必须更改以下代码行。

Set wsO = wb.Sheets("Orders")
dtmDate = .Range("OrderDate").Value
strCust = .Range("CustName").Value
strOrder = .Range("OrderNum").Value

You can also change the date format in the code, if you prefer something different. For example, change the date format to the following.

如果您希望使用其他格式,也可以在代码中更改日期格式。 例如,将日期格式更改为以下格式。

Format(dtmDate, "yyyy-mm-dd")

You could change the position of the items too -- put the date in the Left Footer, and the other information in the Right Footer.

您也可以更改项目的位置-将日期放在左脚,其他信息放在右脚。

下载样本文件 (Download the Sample File)

To get the VBA code, and test the custom footer macro, you can download the Excel Footer Macro sample workbook.

要获取VBA代码并测试自定义页脚宏,您可以下载Excel页脚宏示例工作簿

The file is in Excel 2007/2010 format, and zipped. When you unzip the file and open it, enable macros, so you can run the code.

该文件为Excel 2007/2010格式,并已压缩。 解压缩文件并将其打开时,请启用宏,以便您可以运行代码。

观看Excel页脚宏视频 (Watch the Excel Footer Macro Video)

To see the steps for setting up the named cells, and an explanation of how the code works, you can watch this short Excel video tutorial.

要查看设置命名单元的步骤以及代码如何工作的解释,您可以观看这段简短的Excel视频教程。

演示地址

翻译自: https://contexturesblog.com/archives/2011/09/23/excel-footer-with-formatted-date/

excel更改页眉页脚

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值