+ Reply to Thread
Results 1 to 2 of 2

Inserted picture wont auto size...

  1. #1
    Registered User
    Join Date
    04-24-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    8

    Inserted picture wont auto size...

    Hi, I created a macro (formula below) that when a button is clicked, opens an insert image box, where I select the image, then press open. Upon open, another box appears that asks me to click the range where I want the picture. Its pretty cool. However, I can only get the height to auto-size in the merged cell range. The width varies depending on the picture. Any ideas? I have multiple possible ranges of merged cells where my customers can place pictures, so this "click where you want it" feature is critical, but the image needs to auto size in the merged range of cells they select.

    Sub Button13_Click()
    '
    Dim sFile As Variant, r As Range
    sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
    If sFile = False Then Exit Sub
    On Error Resume Next
    Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
    On Error GoTo 0
    If r Is Nothing Then Exit Sub
    If r.Count > 1 Then Exit Sub
    ActiveSheet.Pictures.Insert (sFile)
    With ActiveSheet.Pictures(ActiveSheet.Pictures.Count)
    .Top = r.Top
    .Left = r.Left
    .Width = r.Width * r.MergeArea.Columns.Count
    .Height = r.Height * r.MergeArea.Rows.Count

    End With
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Inserted picture wont auto size...

    It's because the aspect ratio of the picture is locked by default.

    If you distort that to make it fit a merge cell size it could lose definition.
    Elegant Simplicity............. Not Always

+ 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