Last active
August 30, 2022 18:08
-
-
Save KareemMAX/86b0c2d431a1d6f36065c418c1c05ef1 to your computer and use it in GitHub Desktop.
URLPictureInsert in Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub URLPictureInsert() | |
Dim Pshp As Shape | |
Dim xRg As Range | |
Dim xCol As Long | |
On Error Resume Next | |
Application.ScreenUpdating = False | |
Set Rng = ActiveSheet.Range("G4:G50") | |
For Each cell In Rng | |
filenam = cell | |
ActiveSheet.Pictures.Insert(filenam).Select | |
Set Pshp = Selection.ShapeRange.Item(1) | |
If Pshp Is Nothing Then GoTo lab | |
xCol = cell.Column + 1 | |
Set xRg = Cells(cell.Row, xCol) | |
With Pshp | |
'.LockAspectRatio = msoFalse | |
If .Width > xRg.Width Then .Width = xRg.Width * 2 / 3 | |
If .Height > xRg.Height Then .Height = xRg.Height * 2 / 3 | |
.Top = xRg.Top + (xRg.Height - .Height) / 2 | |
.Left = xRg.Left + (xRg.Width - .Width) / 2 | |
End With | |
ActiveSheet.Shapes.AddPicture Filename:=filenam, linktofile:=msoFalse, _ | |
savewithdocument:=msoCTrue, Left:=Pshp.Left, Top:=Pshp.Top, Width:=Pshp.Width, Height:=Pshp.Height | |
Pshp.Delete | |
lab: | |
Set Pshp = Nothing | |
Range("G4").Select | |
Next | |
Application.ScreenUpdating = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment