Cropping a first page header image with VBA


New Member
Sep 16, 2014
Hello all-powerful MrExcel board,

I have been dabbling with VBA in Excel for a few years and recently rewrote several routines to make them more bulletproof. Here is what I am attempting to do:

  1. Create a new worksheet
  2. Copy the information as needed from another worksheet
  3. Format the new sheet
  4. Insert one image into the first page header
  5. Crop the first page header image
  6. Insert a second image into the subsequent pages' headers
  7. Crop the second pages' header image

I have been successful with all steps but #5. Yesterday I tried using the macro recorder to generate the proper code for what I was failing to do myself. The macro recorder appeared to work perfectly with the exception of one line:

ExecuteExcel4Macro "(16,774,,,,,,,,,18.01)"
I assume this line would properly crop my first page header image properly if I knew what to do with it. I have been unable to execute this line in anyway. I believe this line is the first page header equivalent of:

With Sheets(1).PageSetup.CenterHeaderPicture
        .Height = 774
        .CropTop = 18.01
End With
The lines above successfully removes 0.25" from the top of the image on the second page header.

Changing the above lines to this:

With Sheets(1).PageSetup.FirstPage.CenterHeaderPicture
        .Height = 774
        .CropTop = 18.01
End With

Results in: Run-Time error '438': Object doesn't support this property or method.

Attempting to execute the Macro Recorder line of:

ExecuteExcel4Macro "(16,774,,,,,,,,,18.01)"
Results in: Run-time error '1004': The formula you typed contains an error.

Google searches of my issues have come up empty. Attempts to use ExecuteExcel4Macro properly using the limited data on: Application.ExecuteExcel4Macro Method (Excel) were also unsuccessful. Any help would be appreciated.

I am running Office Professional Plus 2010 (32-bit) on Windows 7 Professional SP1 (64-bit).

Thank you very much for your time,

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...