Insert resized photo into merged cell vba

mpa24

New Member
Joined
May 2, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi everybody. Thanks in advance for taking a look at my dilemma. I thought I figured out the code to insert a picture resized to fit into an area of merged cells (F10) so that it is centered within the area depending on if it is a horizontal or vertical picture. The user upgraded to Windows 10, so now when they insert a picture it is somewhat resized from the original picture (it's a little too big for cell F10), but it is now over in cell Q10! If they pick any pictures taken before the upgrade, the vba works fine and they get resized nicely to fit in F10. :unsure:


VBA Code:
Dim Pic
Dim PicFormat$
Dim MyRange$

PicFormat = "All Image Files (*.bmp; *.gif; *.jpg; *.tif), *.bmp; *.gif; *.jpg; *.tif"
Pic = Application.GetOpenFilename(PicFormat)
If Pic = False Then End
    
Range("F10").Select
MyRange = Selection.Address
    
With ActiveSheet.Pictures.Insert(Pic)
    
    With .ShapeRange
        .LockAspectRatio = msoFalse
        If .Width > .Height Then .Width = Range(MyRange).Width
        If .Height > Range(MyRange).Height Then .Height = Range(MyRange).Height
        Else
            .LockAspectRatio = msoTrue
            .Height = Range(MyRange).Height
            .Left = Range(MyRange).Left + ((Range(MyRange).Width - .Width) / 2)
        End If
    End With
End With
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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