Cropping a first page header image with VBA

bpbusch

New Member
Joined
Sep 16, 2014
Messages
6
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:

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

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

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

Code:
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,
Brian
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top