使用 VBA 将图像从一张纸的页眉/页脚复制到另一张纸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/941559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:27:33  来源:igfitidea点击:

Use VBA to copy an image from headers/footers of one sheet to another

excel-vbapage-setupvbaexcel

提问by tekBlues

I need to write a VBA code to copy a company logo in the headers/footers of one excel sheet to another sheet in another workbook. Any ideas?

我需要编写一个 VBA 代码来将一个 Excel 工作表页眉/页脚中的公司徽标复制到另一个工作簿中的另一个工作表中。有任何想法吗?

回答by jgallant

Excel has a handy Record Macro function.

Excel 有一个方便的记录宏功能。

You can initiate that, Copy the footer over, then stop the recording.

您可以启动,复制页脚,然后停止录制。

Then, review the code, and it should pretty much show you how to do it.

然后,查看代码,它应该会告诉你如何去做。

回答by barrowc

If you are working in anything older than Excel 2007 then it doesn't sound like this is possible without using the original graphic file (e.g. JPG, GIF etc):

如果您使用的是 Excel 2007 之前的版本,那么在不使用原始图形文件(例如 JPG、GIF 等)的情况下,这听起来是不可能的:

Normally, you can copy and paste the headers and footers from one worksheet to another by selecting the worksheets and then using the Header or Footer dialog boxes (click Custom Header or Custom Footer on the Header/Footer tab of the Page Setup dialog box). However, if the original headers and footers contain graphics, the graphics will not propagate to the other worksheets. The only way to work with pictures in headers or footers for multiple worksheets is to select all the worksheets, and then insert a graphic by using the Insert Picture dialog box (click the Insert Picture button), or format the graphic by using the Format Picture dialog box (click the Format Picture button). The original graphic file is needed for this procedure.

source

通常,您可以通过选择工作表,然后使用“页眉”或“页脚”对话框(单击“页面设置”对话框的“页眉/页脚”选项卡上的“自定义页眉”或“自定义页脚”),将页眉和页脚从一个工作表复制并粘贴到另一个工作表。但是,如果原始页眉和页脚包含图形,则图形将不会传播到其他工作表。处理多个工作表页眉或页脚中图片的唯一方法是选择所有工作表,然后使用“插入图片”对话框(单击“插入图片”按钮)插入图形,或使用“设置图片格式”来设置图形格式对话框(单击设置图片格式按钮)。此过程需要原始图形文件。

来源

It may be possible in Excel 2007 - see here

在 Excel 2007 中可能有可能 - 请参阅此处

回答by tekBlues

One workaround is to copy the originalworksheet to the newworkbook:

一种解决方法是将原始工作表复制到工作簿:

   ' macro on the source workbook
    Sheets("Sheet1").Move After:=Workbooks("Book2").Sheets(3)

When you do this, you get a worksheet in the destination workbook with all the features of the original, including footers and headers, you can then copy all the content you want into the new worksheet

执行此操作时,您会在目标工作簿中获得一个包含原始工作表所有功能(包括页脚和页眉)的工作表,然后您可以将所需的所有内容复制到新工作表中