Solved

Insert Picture problem

Posted on 2011-09-27
5
238 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 18

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 41

Accepted Solution

by:
dlmille earned 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now