tags:

views:

562

answers:

3

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?

Thanks, Jill

+6  A: 

Excel has a handy Record Macro function.

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.

Jon
This approach is hugely valuable for any office automation work. It's the "secret API documentation" that makes the Office COM APIs discoverable, at least in my experience.
Guy Starbuck
+1  A: 

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):

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

barrowc
+2  A: 

One workaround is to copy the original worksheet to the new workbook:

   ' 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

tekBlues