Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Insert Picture problem

Posted on 2011-09-27
5
245 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 42

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

829 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