Image quality

eliozo

Board Regular
Joined
Oct 22, 2010
Messages
80
I wrote a code where i can browse a picture and put it in a selected cell in a small size. When clicking on the photo, it will get bigger. The problem is when it gets bigger it looses its quality and not well shown. How can i keep the same quality of the image ?Thank you for your help

VBA Code:
Sub InsertPicture()
    Dim cel As Range, Pic As Object
    With Application.InputBox("Select Cell from Column B to place a Photo and click OK", "Browse Picture", , , , , , 8)
        Set Pic = ActiveSheet.Shapes.AddPicture(FileName:=GetImage, _
            linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=-1, Height:=-1)
             Pic.Top = .Top: Pic.Left = .Left: Pic.Height = .Height
    End With
    With Pic
        .Name = "P" & Format(Now, "yymmddhhmmss")
        .OnAction = "'" & ActiveWorkbook.Name & "'!Resize"
        .ZOrder msoSendToBack
 
    End With
End Sub
 
Private Function GetImage() As String
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Submit"
        .Title = "Select an image file"
        .Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
        If .Show = -1 Then GetImage = .SelectedItems(1) Else End
    End With
End Function
 
Sub Resize()
    Dim shp As Shape: Set shp = ActiveSheet.Shapes(Application.Caller)
    With shp.TopLeftCell
        .Activate
        If shp.Height > .Height Then shp.Height = .Height Else shp.Height = .Height * 7
    End With
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Example illustrating use of ScaleWidth and ScaleHeight properties
Assign macro below to an image, then click on image to test
VBA Code:
Sub ClickOnPic()
    Dim size As Double, cel As Range
 
    Select Case MsgBox(vbTab & "Yes(BIGGER)" & "    " & "No(SMALLER)", vbYesNo, "")
        Case vbYes:     size = 2
        Case vbNo:      size = 0.5
    End Select
 
    ActiveSheet.Shapes(Application.Caller).Select
    With Selection
        Set cel = .TopLeftCell
        .ShapeRange.ScaleWidth size, msoFalse, msoScaleFromTopLeft
        .ShapeRange.ScaleHeight size, msoFalse, msoScaleFromBottomRight
        .Left = cel.Left
        .Top = cel.Top
        cel.Activate
    End With
End Sub

What you need to do:
Amend your code to insert larger image and use ScaleWidth and ScaleHeight properties to make it smaller without affecting quality
.
.
.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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