How to Insert a Company Logo/Image at a pre-defined position inside a Chart Using VBA ?

all4excel

Active Member
Joined
Feb 15, 2008
Messages
435
Dear Board,

I want to add a Company Logo/Image at a pre-defined position inside a Chart..
I can always do it manually, however would like to know whether its possible to do the same using VBA?

clip_image002.gif

<tbody>
</tbody>
I am not sure whether the Picture is seen now


Thanks in advance

Warm Regards
all4excel

<tbody>
</tbody>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Is it possible to put the same Image/Logo on a Chart using a Macro as I tried Recording a Macro it does not reveal the code to work on..

I am not a VBA pro so need some assistance in this..

Thanks in advance
 
Upvote 0
Bump No Response

Please can some guide me on the same I have tried Googling however nothing has come up for the same..

Thanks in advance
 
Upvote 0
Re: Bump No Response

The following macro will insert an image on the active worksheet and place the image at the top left corner of the first chart in the activesheet, and positioned 10 points from the left and top margins of the chart...

Code:
Option Explicit
Sub test()
    Dim ChrtObj             As ChartObject
    Dim Pic                 As Picture
    
    Set ChrtObj = ActiveSheet.ChartObjects(1)
    
    Set Pic = ActiveSheet.Pictures.Insert("C:\Users\Domenic\Desktop\sample.gif") 'change the path and filename accordingly
    
    Pic.Left = ChrtObj.Left + 10
    
    Pic.Top = ChrtObj.Top + 10
    
    
End Sub

To refer to a chart by name, try replacing...

Code:
Set ChrtObj = ActiveSheet.ChartObjects(1)

with

Code:
Set ChrtObj = ActiveSheet.ChartObjects("Chart 2")
 
Upvote 0
WOw thanks a lot again Domenic it works well...
Is there a way to resize the Images before pasting them on the Charts as though the Images appear smaller in their location when they are pasted with the code they increase in size so we can have a Fixed Size for them..if possible..

And lets say that I was handling different Company Charts and all these Company Logos were saved in one folder and each one had a different file extension then would it be possible to get the file extension with the code before placing it over the Chart...I mean I could have a Drop-down to select the Company's Name in the Sheet which would specify which Image needs to be Picked.?

Thanks in advance

Warm Regards
all4excel
 
Upvote 0
I tried Recording a Macro but it did not show up any code but the Size which I would need is as mentioned below :
Size and rotate:
Height = 0.56" and Width = 0.48"
Roation = 0%

Scale
Height = 100% aand Width = 100%
Lock Aspect Ratio = Checked
Relative to Original Picture Size = Checked

Crop
0 for all Parameters

Original Size
Height = 2.51" and Width = 2.18"

I also do not understand that ideally when we record the Macro some codes are never shown , SO is it that I am missing something or its that some codes would never be revealed..

Thanks in advance..


I would normally have lets say 10 Company Logos in the folder and if every Image has different properties then how can I manage that If I have some Lookup mechanism to Pull the Image based on the company name selected in the Drop-down.
 
Upvote 0
Found something :

Code:
[COLOR=#333333]    Dim shpTemp As Shape[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit;">    Dim rngCell As Range        Set rngCell = ActiveCell    Set shpTemp = ActiveSheet.Shapes(1)        With shpTemp        .LockAspectRatio = False        .Left = rngCell.Left        .Top = rngCell.Top        .Width = rngCell.Width        .Height = rngCell.Height </code></pre>[COLOR=#333333]    End With[/COLOR]

But don't know how to specify the SIZE
 
Upvote 0
I did manage to get it but still dont know how to merge it but this works..

I dont know know how though...

Code:
Sub Insert_ImageOnChart()    Dim ChrtObj             As ChartObject
    Dim Pic                 As Picture
    
    Set ChrtObj = ActiveSheet.ChartObjects(1)
    


    Set Pic = ActiveSheet.Pictures.Insert("C:\Documents and Settings\Administrator\Desktop\MickeyMouse.jpg") 'change the path and filename accordingly


    
    Pic.Left = ChrtObj.Left + 2
    
    Pic.Top = ChrtObj.Top + 3
    
    
'            'Pic.Left = .Left
            Pic.ShapeRange.LockAspectRatio = msoFalse
            Pic.Placement = xlMoveAndSize
            Pic.ShapeRange.Width = Pic.ShapeRange.Width / 4.1     '0.44
            Pic.ShapeRange.Height = Pic.ShapeRange.Height / 4.1  '0.51
'
    
End Sub

Can you please some explanation..

Warm Regards
all4excel
 
Upvote 0
Unfortunately, if you're using Excel 2007, the macro recorder is useless when it comes to pictures, and has been downgraded when it comes to charts. Try...

Code:
Option Explicit
Sub test()
    Dim ChrtObj             As ChartObject
    Dim Pic                 As Picture
   
    Set ChrtObj = ActiveSheet.ChartObjects(1)
   
    Set Pic = ActiveSheet.Pictures.Insert("C:\Documents and Settings\Administrator\Desktop\MickeyMouse.jpg")
   
    With Pic
        .Left = ChrtObj.Left + 2
        .Top = ChrtObj.Top + 3
        .ShapeRange.LockAspectRatio = msoFalse
        .Width = Application.InchesToPoints(0.48)
        .Height = Application.InchesToPoints(0.56)
        .ShapeRange.LockAspectRatio = msoTrue
    End With
   
    ActiveSheet.Shapes.Range(Array(ChrtObj.Name, Pic.Name)).Group
   
End Sub
</SPAN>
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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