Formula Checked - Resizing Image

Joined
May 9, 2018
Messages
5
Please Gurus,

Help me change this formula, I want the size of the image which is inserted is to be exactly the size I wanted (or automatically as big as the size of the cell). Thanks in advance

VBA Code:
Sub INSERT_PICTURE_DIALOG()
    '---------------------------------------------------------------------------
    '- SELECTED CELL
    Dim MyCell As Range
    Set MyCell = ActiveCell
    '---------------------------------------------------------------------------
    '- EXCEL INSERT PICTURE DIALOG. **AUTOMATIC INSERTION**.
    rsp = Application.Dialogs(xlDialogInsertPicture).Show
    If rsp = False Then Exit Sub
    '---------------------------------------------------------------------------
    '- RESIZE PICTURE TO CELL. CHANGE ITS NAME. REFORMAT
    With MyCell
        .Value = MyFile         ' put the file name into the cell
        '-
        Selection.Name = "MyName"
        Selection.Top = .Top
        Selection.Left = .Left
        Selection.Width = .Width
        Selection.Height = .Height
        Selection.ShapeRange.PictureFormat.Brightness = 0.5 ' various formats available
        Selection.Placement = xlMoveAndSize ' move and size with cells
        Selection.PrintObject = True
        '-
        .Select                 ' change focus (selection) from picture to cell
    End With
    '--------------------------------------------------------------------------
    Beep
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Something like this perhaps ...
VBA Code:
Sub INSERT_PICTURE_DIALOG_r2()

    Const cBorder       As Double = 5       ' << change as required
    Const cLockRatio    As Boolean = True   ' << change as required
    
    Dim sPicture As String, pic As Picture
    
    sPicture = Application.GetOpenFilename("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", , "Select Picture to Import")
    If sPicture = "False" Then Exit Sub
    Set pic = ActiveSheet.Pictures.Insert(sPicture)
    With pic
        .ShapeRange.LockAspectRatio = cLockRatio
        ActiveCell.Value = .Name
        If Not .ShapeRange.LockAspectRatio Then
            .Width = ActiveCell.MergeArea.Width - (2 * cBorder)
            .Height = ActiveCell.MergeArea.Height - (2 * cBorder)
        Else
            If .Width >= .Height Then
                .Width = ActiveCell.MergeArea.Width - (2 * cBorder)
            Else
                .Height = ActiveCell.MergeArea.Height - (2 * cBorder)
            End If
        End If
        .Top = ActiveCell.MergeArea.Top + cBorder
        .Left = ActiveCell.MergeArea.Left + cBorder
        .Placement = xlMoveAndSize
        .PrintObject = True
    End With
    
    Set pic = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top