Adding logo to multiple worksheets

Craig1

Active Member
Joined
Jun 11, 2009
Messages
322
Hi All,
I am using the code below to add logo's to multiple worksheets. It works great until I send the workbooks to my colleagues. The logo isn't visible for them, I believe it's because it is creating a link to the picture in my own personal drive, I want to embed the logo, could I change the code to embed? When go to my colleagues PC it shows the error "The linked image cannot be displayed" but when I check for links there isn't any, so I think the easiest way will be to modify the code.
Sub AddPicMain()

Dim myPicture As Variant
Dim p As Object
Dim Factor As Single
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.cgm; *.jpg; *.bmp; *.tif),*.gif; *.cgm; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")
If myPicture = False Then Exit Sub
For Each Page In Sheets
Page.Activate
Range("A1").Select
Set p = ActiveSheet.Pictures.Insert(myPicture)
'Width and Height are in points (1/72 inch)
p.ShapeRange.LockAspectRatio = msoTrue
Hfactor = 1.5 / (p.Height / 72)
Wfactor = 7 / (p.Width / 72)
If Hfactor < Wfactor Then
Factor = Hfactor
Else
Factor = Wfactor
End If
p.Width = p.Width * Factor
p.Height = p.Height * Factor

Next
End Sub

Thanks in advance Craig.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Thanks for the reply Yongle,
I'm struggling a little to get this method to do the exact same thing.

Craig.
 
Upvote 0
This should get you started
- I have added declarations for ALL variables
- it does help when your code does not work as planned etc

Code:
Sub AddPicMain()

    Dim myPicture As Variant, [COLOR=#008080]Page As Variant, Hfactor As Double, Wfactor As Double,[/COLOR][COLOR=#008080]p As Shape[/COLOR]
    Dim Factor As Single
        myPicture = Application.GetOpenFilename _
            ("Pictures (*.gif; *.cgm; *.jpg; *.bmp; *.tif),*.gif; *.cgm; *.jpg; *.bmp; *.tif", _
                , "Select Picture to Import")
    If myPicture = False Then Exit Sub
    For Each Page In Sheets
        Page.Activate
        Range("A1").Select
        Set p = ActiveSheet.Shapes.AddPicture(myPicture, True, True, Range("A1").Left, Range("A1").Top, -1, -1)
        p.LockAspectRatio = msoTrue
        Hfactor = 1.5 / (p.Height / 72)
        Wfactor = 7 / (p.Width / 72)
        If Hfactor < Wfactor Then
            Factor = Hfactor
        Else
           Factor = Wfactor
        End If
        p.Width = p.Width * Factor
        p.Height = p.Height * Factor
    Next
End Sub
 
Upvote 0
Yongle, Thanks for that, it works great.
Does exactly what it says on the tin.

Thanks Again.

Craig.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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