Solved

Insert Picture problem

Posted on 2011-09-27
5
252 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
[X]
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
  • 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 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

695 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