Variable Image in Header

GrahamVincent

New Member
Joined
Mar 3, 2009
Messages
5
Hi all

I have a macro that inserts an image into the header based on a variable held in a cell. (see below)

This works OK (if a little slowly) up to and including the RightHeader on the first worksheet (SH1).
However nothing is appearing in the header in the second sheet (SH2).

Am I missing something obvious?
Any help would be much appreciated

Feel free to critique, disect or chuckle :)



Sub InsertPicture()

Dim wb As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim vStr As String


Set wb = ThisWorkbook
Set SH1 = wb.Worksheets("Insurer")
Set SH2 = wb.Worksheets("Charts")

vStr = SH1.Range("T4").Text



With SH1.PageSetup.CenterHeaderPicture
.Filename = vStr
.Height = 200
.Width = 250
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.39
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
' Enable the image to show up in the left header.
ActiveSheet.PageSetup.CenterHeader = "&G"

With SH1.PageSetup.RightHeaderPicture
.Filename = "G:\MI\Insurer MI\New Suite Insurer Reports\TEST\LOGOS\MCDLogo.gif"
.Height = 45
.Width = 67.5
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.39
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
' Enable the image to show up in the left header.
ActiveSheet.PageSetup.RightHeader = "&G"

With SH2.PageSetup.CenterHeaderPicture
.Filename = vStr
.Height = 200
.Width = 250
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.39
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
' Enable the image to show up in the left header.
ActiveSheet.PageSetup.CenterHeader = "&G"

With SH2.PageSetup.RightHeaderPicture
.Filename = "G:\MI\Insurer MI\New Suite Insurer Reports\TEST\LOGOS\MCDLogo.gif"
.Height = 45
.Width = 67.5
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.39
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
' Enable the image to show up in the left header.
ActiveSheet.PageSetup.RightHeader = "&G"

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Welcome to the Board.

Is it because you are using ActiveSheet rather than SH2 in eg?

ActiveSheet.PageSetup.CenterHeader = "&G"
 
Upvote 0
Many thanks for your welcome & quick response Andrew.

Have changed active sheet to SH1&2 and all's well.
That's the problem with copy&paste

With regards to the slowness, can the two sets of instructions for headers be combined in any way?

thanks again
Graham
 
Upvote 0

Forum statistics

Threads
1,203,127
Messages
6,053,667
Members
444,677
Latest member
LWilliamsAtchristies

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