Zoom Picture in and out

User avatar
Stefan_Sand
3StarLounger
Posts: 398
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Zoom Picture in and out

Post by Stefan_Sand »

Hello,

i have a nice worksheet, where i can import pictures and zoom them out and in on a click. But, is there a way to zoom the pictures out bgger than their size in the same folder -> for example the are imported into cells d25 to j25 if you set the name of the pictures from cells d24 to j24.
after clicking, these pics will be zoomed out to their picture size. I cannot set the zoom taller than this. Is there a way to do this in my code - for example 2 times bigger?

Stef
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 73820
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Zoom Picture in and out

Post by HansV »

Change the lines

Code: Select all

    bu = Range(rng).Width
    su = Range(rng).Height
to for example

Code: Select all

    bu = 2 * Range(rng).Width
    su = 2 * Range(rng).Height
Regards,
Hans

User avatar
Stefan_Sand
3StarLounger
Posts: 398
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Zoom Picture in and out

Post by Stefan_Sand »

Hi Hans, thanks for the quick answer, but this is, what i tried. It enlarges the picture to double size, but prevents from reducing to its original size after the zoomiong out.
best regards,
Stef

User avatar
HansV
Administrator
Posts: 73820
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Zoom Picture in and out

Post by HansV »

To what size should the pictures be reduced? This is what I get (you didn't bother including the images):

S0864.png
S0865.png
You do not have the required permissions to view the files attached to this post.
Regards,
Hans

User avatar
Stefan_Sand
3StarLounger
Posts: 398
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Zoom Picture in and out

Post by Stefan_Sand »

when you import the picture first, it is set to the cell size - that is , what should be the "origin" size. when you click, it zoomes out to its size (if you open it in paint or so) - for example, the size of the first picture - Beschaffung.jpg is 361 KB (2325 Pixel - Horizontal , 2425 -Vertical Pixel)...
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 73820
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Zoom Picture in and out

Post by HansV »

Try this:

Code: Select all

Sub ViewPicture()
    Dim shp As Shape, rng As Range

    Set shp = ActiveSheet.Shapes(Application.Caller)
    Set rng = shp.TopLeftCell

    If shp.Width = rng.Width Then
        With shp
            .LockAspectRatio = msoFalse
            .Height = 2 * rng.Height
            .Width = 2 * rng.Width
            .ZOrder msoSendToBack
        End With
    Else
        With shp
            .LockAspectRatio = msoFalse
            .Height = rng.Height
            .Width = rng.Width
            .ZOrder msoBringToFront
        End With
    End If
End Sub
Regards,
Hans

kadrleyn
NewLounger
Posts: 1
Joined: 28 Jan 2021, 17:58

Re: Zoom Picture in and out

Post by kadrleyn »

Hi,
review this tutorial about image zoom: https://eksi30.com/insert-picture-in-ce ... ell-value/
You do not have the required permissions to view the files attached to this post.

SpeakEasy
2StarLounger
Posts: 173
Joined: 27 Jun 2021, 10:46

Re: Zoom Picture in and out

Post by SpeakEasy »

Er ... that seems to be exactly the example code Stef is using ...

SpeakEasy
2StarLounger
Posts: 173
Joined: 27 Jun 2021, 10:46

Re: Zoom Picture in and out

Post by SpeakEasy »

Use ScaleHeight and ScaleWidth instead

Code: Select all

    With shp
            .LockAspectRatio = msoFalse
            .ScaleHeight 2, msoTrue ' Twice height
            .ScaleWidth 2, msoTrue ' twice width
            .ZOrder msoSendToBack
    End With

User avatar
Stefan_Sand
3StarLounger
Posts: 398
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Zoom Picture in and out

Post by Stefan_Sand »

There is even the reference to eksi30 in it.