VBA: Insert URL Photos

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi, two questions.
  1. How do I insert the pictures via hyperlink, as an object so someone external can view the pictures. I tried to modify it but it returning a " ... End With" error.
  2. Also, can I change this script to designate which column to insert the photos into? For example, I want to insert the pictures in column A.

VBA Code:
Sub InstallPictures()

    Dim i As Long, v As String, Pic

    On Error Resume Next

    For i = 1 To 1903

        v = Cells(i, "G").Value

        If v = "" Then Exit Sub

        Set Pic = ActiveSheet.Pictures.Insert(v)

        With Pic

            .LockAspectRatio = msoFalse

            .Width = 100

            .Height = 100

            .Left = Cells(i, "h").Left + Cells(i, "h").Left.Width / 2 - .Width / 2

            .Top = Cells(i, "h").Top + Cells(i, "h").Height / 2 - .Height / 2

        End With

    Next i

    On Error GoTo 0

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
There was no End if, fixed that part.

Does it insert them into H? Change the "H" to "A" in .Top and .Left

VBA Code:
Sub InstallPictures()

    Dim i As Long, v As String, Pic

    On Error Resume Next

    For i = 1 To 1903

        v = Cells(i, "G").Value

        If v = "" Then Exit Sub
        End If

            Set Pic = ActiveSheet.Pictures.Insert(v)

            With Pic

            .LockAspectRatio = msoFalse

            .Width = 100

            .Height = 100

            .Left = Cells(i, "h").Left + Cells(i, "h").Left.Width / 2 - .Width / 2

            .Top = Cells(i, "h").Top + Cells(i, "h").Height / 2 - .Height / 2

            End With

    Next i

    On Error GoTo 0

End Sub
 
Upvote 0

mrshl9898 Thank you for taking the time to provide a solution.​

I tried your script and encountered an error. I don't know what it mean.
To answer your question, yes, the photos are meant to be inserted into H, but I can try inserting into A as well.

Error
"End if without block if"
VBA Code:
If v = "" Then Exit Sub
        End If
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,490
Members
448,967
Latest member
visheshkotha

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