?
Solved

Insert Picture problem

Posted on 2011-09-27
5
Medium Priority
?
268 Views
Last Modified: 2012-08-13
Hi All,

I have the following code that goes out to my network, grabs a picture from a particular directory and pastes to my excel sheet.  Then the excel sheet gets automatically emails out to people.  What I just noticed is that the people I send to, they dont have access to same network folders, so they cannot see image.  Is there a way to hardcode picture in excel?


InsertPictureInRange "I:\Macro\Database\JeffLogo.jpg", Range("A1")

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' import picture
    Set p = ActiveSheet.Pictures.Insert(PictureFileName)
    ' determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, 3.75).Left - .Left
        h = .Offset(3.75, 0).Top - .Top
    End With
    ' position picture
    With p
        .Top = t
        .Left = l
        .Width = w
        .Height = h
    End With
    Set p = Nothing
End Sub

Open in new window

0
Comment
Question by:solarissf
  • 3
5 Comments
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 36712700
I think you are okay in how you create the file.
Since you email the file out, send it as a PDF and the image will be converted.
You did not specify a version to work with and options vary by version.
0
 

Author Comment

by:solarissf
ID: 36712727
Unfortunately I need to leave in excel format.
0
 

Author Comment

by:solarissf
ID: 36712729
I am also using excel 2010
0
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 total points
ID: 36712859
Use AddPicture to embed the document in the workbook:  From Excel Help:

Shapes.AddPicture Method
Creates a picture from an existing file. Returns a Shape object that represents the new picture.
Syntax

expression.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)

expression   A variable that represents a Shapes object.

Parameters

Name Required/Optional Data Type Description
Filename Required String The file from which the OLE object is to be created.
LinkToFile Required MsoTriState The file to link to.
SaveWithDocument Required MsoTriState To save the picture with the document.
Left Required Single The position (in points) of the upper-left corner of the picture relative to the upper-left corner of the document.
Top Required Single The position (in points) of the upper-left corner of the picture relative to the top of the document.
Width Required Single The width of the picture, in points.
Height Required Single The height of the picture, in points.

EXAMPLE:
Dim sht As Worksheet
Set sht = ActiveSheet

EXAMPLE:  mysht.Shapes.AddPicture "C:\Users\Dave\Desktop\example.jpg", True, msoCTrue, 75, 75, 75, 75
Dave
0
 

Author Comment

by:solarissf
ID: 36716281
perfect, works... thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question