Script to resize the picture selected.

Foppa21

New Member
Joined
Feb 14, 2013
Messages
1
Hello, I was wondering if someone could help me with the following code? I'm basically trying to create thumbnails then have them enlarge once you click on them. I can make it work for a single picture like "Picture 6" but then I'd have to write a separate macro for each one.

Is there a way I can do this such that instead of calling each picture I can use something like "Selected picture"?

I'm new to this and most of what I've developed so far is what I've garnered from the web.

Help is greatly appreciated! Code is as follows:

Sub Picture5_Click()
ActiveSheet.Shapes("Picture 6").Select
If Selection.Width < 100 Then Enlarge Else Reduce
End Sub

Sub Enlarge()
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.Placement = xlMoveAndSize
Selection.ShapeRange.Width = 5 * Selection.ShapeRange.Width
ActiveSheet.Range("B128").Select
End Sub
Sub Reduce()
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.Placement = xlMoveAndSize
Selection.ShapeRange.Width = 0.2 * Selection.ShapeRange.Width
ActiveSheet.Range("B128").Select
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You can use Application.Caller to refer to the shape:


Code:
Sub Picture1_Click()
    ResizePicture      '<-- same for all shapes you wish to size...
End Sub

Sub ResizePicture()
    With ActiveSheet.Shapes(Application.Caller)
        .Width = .Width * 1.2
        .Height = .Height * 1.2
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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