Placing Different Picture in first page header than all other pages

dharnen

New Member
Joined
Jan 30, 2015
Messages
5
This is my first time posting anything so please excuse my lack of post formatting. I've been using this forum the past couple of months to help solve small vba issues I've come across while developing a semi-program in excel. It does a bunch of things I'd rather not explain but ive gotten to the point where I need to set the headder and footer for each page on each sheet. I've gotten where I want to place an image in the header to resemble a predetmined header layout but I need to make the first page a differnet picture than all the other pages. I can successfully place an image in the first page that translates to all the others as well as a place one on all the others but not the first. When I turn "PageSetup.DifferentFirstPageHeaderFooter = True" and try to access the second or first page properties exclusively it give me an error stating that the property I'm trying to access is not valid. Below is an example of the part of my code I've having trouble with.

--------------------------------------------------

Sheets(curSheet).PageSetup.DifferentFirstPageHeaderFooter = True


Call GIF_Snapshot(HeaderTemplate.Range("B1:L8")) 'This just ceates a picture in a known location and with a known name that I input into the center header


Sheets(curSheet).PageSetup.TopMargin = Application.InchesToPoints(2.01)
Sheets(curSheet).PageSetup.LeftHeader = ""
Sheets(curSheet).PageSetup.CenterHeader = "&G"
Sheets(curSheet).PageSetup.RightHeader = ""
Sheets(curSheet).PageSetup.CenterHeaderPicture.Filename = "Location\headertemplate.gif"
Sheets(curSheet).PageSetup.RightFooter = "&BFINAL INSPECTION: _________"


Call GIF_Snapshot(HeaderTemplate.Range("B11:L13")) 'Same thing as above but different visual



Sheets(curSheet).PageSetup.Pages(2).LeftHeader = ""
Sheets(curSheet).PageSetup.Pages(2).CenterHeader = "&G"
Sheets(curSheet).PageSetup.Pages(2).RightHeader = ""
Sheets(curSheet).PageSetup.Pages(2).TopMargin.CenterHeaderPicture.Filename = "Location\headertemplate.gif"
Sheets(curSheet).PageSetup.Pages(2).RightFooter = "&BFINAL INSPECTION: _________"


-------------------------------------------------
I've tried accessing different properites and simplifying my code to use a 'with' property but I've just written it out the long way to try to debug. The first chunk of code should work and will place my visual in the header on all pages excep the first. I guess what I'm really looking for is how do I access the header and footer on just the first page to insert a new visual or is this not possible in excel. I know I can use:

Sheets(curSheet).PageSetup.CenterHeader.FirstPage.Text = "Some Text"

but thats text only not a picuture or (&G).

If someone could shed some light on my dilemma I would greatly appreciate it!!

Thanks,
dharnen
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It appears that from the user interface, that you can't insert a picture on the First Page header.

You could put it on the worksheet.
 
Upvote 0
I could but that would cause me to reformat what was already existing on that page and have a blank header. Using the user interface (not VBA) I can accomplish what I want to do so I believe it is possible with code. I just don't know what the correct syntax is for vba.
 
Upvote 0
In Excel 2010, I can't do it from the UI.
 
Upvote 0
If you can do it in your version, have you tried recording a macro?
 
Upvote 0
Thats a good idea. I'll try it out. For reference to place a picture on the first page header you would click: View->Page Layout (in teh Workbook Views panel)-> Then click on the header section you want to add somthing to -> Click on the design tab for the Header & Footer Tools -> Picture (in the Header & Footer Elements) - > Then locate your picture.
 
Upvote 0
Sorry, I was looking at the wrong icon.

Code:
  With Sheet1
    .PageSetup.FirstPage.CenterHeader.Picture.Filename = "C:\Users\shg\Pictures\shg Pics\Pot of Gold.jpg"
    .PageSetup.CenterHeaderPicture.Filename = "C:\Users\shg\Pictures\shg Pics\apple.gif"
  End With
 
Upvote 0
Yea thats what I saw as well. It seems that the ".PageSetup.FirstPage.CenterHeader.Picture.Filename = "C:\Users\shg\Pictures\shg Pics\Pot of Gold.jpg"" line is what I was looking for. I also found that if you use a written macro the picture may not show up ulness there is already a picture designated for that section so to get around that you can use: "Sheets(curSheet).PageSetup.FirstPage.CenterHeader.Text = "&G"" to initailize the picture and then follow up the next line with the filename. Thanks for your help!!

=)
 
Upvote 0
Glad you got it sorted, and sorry for the miscue.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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