Loop URL links through range

Sahak

Well-known Member
Joined
Nov 10, 2006
Messages
1,012
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Hi All,

I have big list of URL links having jpg pictures.

I would like a VBA code, which will loop trough rows, and if the link does not have a picture, then color that cell yellow, if there is a picture, then go to check next cell (No need to open the picture)

Here are some links for example

 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Upvote 0
Thank you very much for repy. Unfortunaly this not what I want.
I apologize for not explaining in detail. The point is that all the link list is prepared in advance, and all of them have .jpg at the end, and not all pictures put on the web, we put them partialy, that is the reasun why we want to know which link has picture, which link does not.
 
Upvote 0
Okay, but how do you determine, what is a picture and what is not a picture?

The VBA "program" can only do, what a human would do, but automated.

So how would you sort out a link without a picture? What would you do?
 
Upvote 0
The URL address is one only; it is the same for all pictures, in my example: http://www.abcdefg.com/albums/
We add a picture with extension “.jpg” in folder “albums” with picture name, for example “MG407B”, after that, if we click on link “http://www.abcdefg.com/albums/MG407B.jpg” on Excel worksheet, we will see that existing picture, but if we click on link “http://www.abcdefg.com/albums/MG105N.jpg”, it will give an error, because there is no picture named “MG105N.jpg” in folder.
Because we have too many pictures, it is more convenient and much easier (copy, paste …) to put the URL addresses on Excel worksheet first, than to put the picture in a folder, and then put the URL addresses on Excel worksheet.
 
Upvote 0
Here is another option. Try the below code and change the Data Range to suit your needs: Set Data = ActiveSheet.Range("A1:A2")




VBA Code:
Option Explicit

Sub HighlightURLs()
   Dim DataCell As Range
   Dim Data As Range
   Set Data = ActiveSheet.Range("A1:A2") '<-- user defined Range
   
   For Each DataCell In Data
      If HttpResponseOk(DataCell.Value2) Then DataCell.Interior.Color = RGB(255, 255, 0)
   Next DataCell
End Sub

Private Function HttpResponseOk(URL As String) As Boolean
   Dim request As Object
   Set request = CreateObject("WinHttp.WinHttpRequest.5.1")
   On Error Resume Next
   request.Open "HEAD", URL
   request.send
   If request.Status = 200 Then
      HttpResponseOk = True
   Else
      HttpResponseOk = False
   End If
End Function
 
Upvote 1
Solution
Yes, this is what I wanted.(y)
Thank you very much, and God bless you.
 
Upvote 0
Glad I could help. Thanks for the feedback.
If you encounter any problems don't hesitate to ask.

Please mark the answer as solution if it's exactly what you needed :)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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