+ Reply to Thread
Results 1 to 4 of 4

insert a photo (any file type), resize it, and place it in a specific location.

Hybrid View

  1. #1
    Registered User
    Join Date
    03-12-2010
    Location
    Kansas City, Missouri
    MS-Off Ver
    Excel 2003
    Posts
    26

    insert a photo (any file type), resize it, and place it in a specific location.

    To date i have the following code written.

    Sub InsertPhoto()
    Range("E7").Select
    ActiveSheet.Pictures.Insert( _
    Application.GetOpenFilename( _
    "JPG picture files (*.jpg),*.jpg", , "Select the picture")).Select
    Selection.ShapeRange.LockAspectRatio = msoTrue
        Selection.ShapeRange.Height = 800
        Selection.ShapeRange.Width = 343
    End Sub
    With the code shown above I am only able to post JPeg images and I get a run time error when I attempt to cancel out of the search window (when selecting a file to insert).

    Can someone tell me what I need to do to allow my searches to cancel and allow me to search for and resize all file types and not simply JPeg images.

    Thanks.
    Last edited by jaganath; 05-05-2010 at 10:39 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: insert a photo (any file type), resize it, and place it in a specific location.

    Try this:

    Option Explicit
    
    Sub InsertPhoto()
    Dim fName As String
    
    Range("E7").Select
    fName = Application.GetOpenFilename("Picture files (*.jpg;*.gif;*.bmp), *.jpgs;*.gif;*.bmp", , _
                "Select the picture")
    If fName = "False" Then Exit Sub
    
    ActiveSheet.Pictures.Insert(fName).Select
                        
    Selection.ShapeRange.LockAspectRatio = msoTrue
        Selection.ShapeRange.Height = 800
        Selection.ShapeRange.Width = 343
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-12-2010
    Location
    Kansas City, Missouri
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: insert a photo (any file type), resize it, and place it in a specific location.

    perfect! thanks.

  4. #4
    Registered User
    Join Date
    10-19-2010
    Location
    netherlands
    MS-Off Ver
    Excel 2007, 2010 (Win 7 x64)
    Posts
    10

    Re: insert a photo (any file type), resize it, and place it in a specific location.

    it places the picture, it resize it, but it don't place it in a specific location.. (in this place not in "E7")
    at least not for me. it places it in the left top corner, about 2 cm away from the sides

    how can you directly place a picture in the cell you want?

    Edit:
    I searched further on this forum and found the answer. for those who need this code, i'll post it with a small addition so it will save you search time.
    Sub InsertPhoto()
    Dim fName As String
    
    Range("E7").Select
    fName = Application.GetOpenFilename("Picture files (*.jpg;*.gif;*.bmp), *.jpgs;*.gif;*.bmp", , _
                "Select the picture")
    If fName = "False" Then Exit Sub
    
    ActiveSheet.Pictures.Insert(fName).Select
         With Selection.ShapeRange
            .LockAspectRatio = msoTrue
            .Top = Range("E7").Top
            .Left = Range("E7").Left
            .Height = Range("E7").Height
            .Width = Range("E7").Width
        End With                 
    
    End Sub
    (this probably only make a difference on excel 2007
    Last edited by ditisFloris; 10-19-2010 at 09:36 AM. Reason: found the answer

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1