Insert Picture Macro Only Reliably Works on Landscape Photos

Realtreegirl75

New Member
Joined
Aug 28, 2022
Messages
31
Office Version
  1. 365
Platform
  1. Windows
I'm working on a document for work and I need to have an "insert picture" button. I have a button with code that reliably works for landscape photos and puts them where the need to go(A100:AJ137), resizes, renames, etc. but the code only works for some portrait photos. Most of the time it drops portrait photos into (F95:AP128). The other catch is that this works on my work computer but not my personal computer?? I'm quite new to VBA so I'm still working through a lot of the things I'm trying to figure out on forums and youtube. The code for one of my insert picture buttons is below and any input would be greatly appreciated!

Sub GetPic2()
Dim fNameAndPath As Variant
Dim Img As Picture
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set Img = ActiveSheet.Pictures.Insert(fNameAndPath)
With Img
On Error Resume Next
ActiveSheet.Pictures("A100").Delete

If .Width > .Height Then
.ShapeRange.LockAspectRatio = msoFalse
.Left = ActiveSheet.Range("A100").Left
.Top = ActiveSheet.Range("A100").Top
.Width = ActiveSheet.Range("A100:AJ100").Width
.Name = "A100"
.PrintObject = True
Else
If .Height > .Width Then
.ShapeRange.LockAspectRatio = msoFalse
.Left = ActiveSheet.Range("A100").Left
.Top = ActiveSheet.Range("A100").Top
.Height = ActiveSheet.Range("A100:A137").Height
.Name = "A100"
.PrintObject = True
End If
End If

End With

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Something else I just discovered....the macro works with pictures that I have dowloaded from Facebook or Google...any photo I've taken myself is put in the wrong location and not resized correctly.
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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