Browse picture and enlarge it

eliozo

Board Regular
Joined
Oct 22, 2010
Messages
80
I need to create a button where i can browse a picture and put it in cell E5 for example (technically it should be small). When i click on it, it should become bigger and when i click on it again it should take place again in cell E5. Please help..

Plus if I need to create another button where i want to print this picture but in a bigger scale, how should i do it ? Thank you so much !!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I need to create a button where i can browse a picture and put it in cell E5 for example (technically it should be small). When i click on it, it should become bigger and when i click on it again it should take place again in cell E5

Does this do what you want?
Assign this macro to any shape and click on the shape
It toggles betweeen small and large

VBA Code:
Sub EnlargePicture()
    Dim shp As Shape, cel As Range, h As Double
    Set shp = ActiveSheet.Shapes(Application.Caller)
    Set cel = shp.TopLeftCell
    cel.Activate
    h = cel.Height
    With shp
        .Top = cel.Top
        If .Height > h Then .Height = h Else .Height = h * 3
    End With
End Sub
 
Upvote 0
The photos are not uploaded in the file to assign them to your macro. I want to create a button where i can browse a photo from my computer and make it small in cell E5 for example. Then, when clicking on the photo it can become bigger or back to her small initial shape.
Plus if you can help me with the print question too thank you
 
Upvote 0
I need to create a button where i can browse a picture and put it in cell E5 for example (technically it should be small). When i click on it, it should become bigger and when i click on it again it should take place again in cell E5. Please help..


Try this:
Place the code below in a module
Add a button to the worksheet
Assign InsertPicture to the button

To test
Click on the button
Select cell to place image
Browse to image and click Submit
Click on the image

VBA Code:
Sub InsertPicture()
    Dim cel As Range, pic As Object
    With Application.InputBox("Select Cel to place Shape and click OK", "Shape Placement", , , , , , 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
    pic.OnAction = "'" & ActiveWorkbook.Name & "'!Resize"
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 * 20
    End With
End Sub
 
Upvote 0
Thank you for your help ! I got this message when clicking on the picture: “ambiguous name detected: Resize”
 
Upvote 0
More than one picture has the same name
Replace InsertPicture with code below to avoid risk of duplicated names in future

VBA Code:
Sub InsertPicture()
    Dim cel As Range, pic As Object
    With Application.InputBox("Select Cel to place Shape and click OK", "Shape Placement", , , , , , 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"
    End With
End Sub
 
Upvote 0
It is still the same error knowing that i only put one image and when clicking on it it gives me the error message “ambiguous name detected: resize”
 
Upvote 0
Ah ...
- I did not fully engage brain before replying last time :oops:
- I think you have you more than one sub named Resize (either in the same module or another module)
- delete the others
 
Upvote 0
Can you help me with this please:
The same tactic you used to upload a picture by selecting a cell, but now i want to put a button “print” where when i click on it, it asks me what cell do you want to print; then it prints the cell selected and the 4 other cells beside it on the right.
Thank you !!
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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