WildBurrow
New Member
- Joined
- Apr 5, 2021
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
I'm creating a photo log template that will allow Users to select up to four images (portrait orientation) per sheet. The pictures should be aligned with the top right position of cells A1, S1, A26, and S26. Under each picture, there are two cells that allow for User input: Direction of View" and "Description of View". I envision four command buttons (one for each of the picture placeholders) that will prompt the User to select the picture then insert the picture and resize to fit the specific area while maintaining an aspect ratio of the original picture.
I've cobbled together some code but it places the picture where it wants to, regardless of how I try to define the desired cell location. Can anyone help me fine tune this?
I've cobbled together some code but it places the picture where it wants to, regardless of how I try to define the desired cell location. Can anyone help me fine tune this?
VBA Code:
Private Sub Insert1of4Portrait()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Insert"
.Title = "Select an image file"
.Filters.Clear
.Filters.Add "JPG", "*.JPG"
.Filters.Add "JPEG File Interchange Format", "*.JPEG"
.Filters.Add "Graphics Interchange Format", "*.GIF"
.Filters.Add "Portable Network Graphics", "*.PNG"
.Filters.Add "Tag Image File Format", "*.TIFF"
.Filters.Add "All Pictures", "*.*"
If .Show = -1 Then
Dim img As Object
Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))
With img
.Top = Range("S26").Top
.Left = Range("S26").Left
.ShapeRange.LockAspectRatio = msoTrue
.Width = 279
End With
Else
MsgBox ("Picture Insert Cancelled")
End If
End With
End Sub