loop of urls

eran3185

Board Regular
Joined
Apr 28, 2007
Messages
142
Hi
I have a code that open a webpage then copy it and paste on a1
I want to know if there is a way to add a loop that take 10 webpages and paste tham on columns a1-i1
my code:
Sub test()

On Error Resume Next

Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")


IE.Navigate "CNN International - Breaking News, US News, World News and Video"


Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop

'Wait for window to open!
Application.Wait (Now + TimeValue("0:00:01"))

IE.Visible = True


IE.ExecWB 17, 0 '// SelectAll

Application.Wait (Now + TimeValue("0:00:01"))



IE.ExecWB 12, 2 '// Copy selection

Application.Wait (Now + TimeValue("0:00:01"))

IE.Quit
' End With
Set IE = Nothing

Application.Wait (Now + TimeValue("0:00:01"))

Range("A1").Select
ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, _
DisplayAsIcon:=False


Application.CutCopyMode = False



End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Where do you have the 10 url?
Always paste in A1:I1?
 
Upvote 0
I have more urls that I want to write them on column t1:t10
I want that the loop will go on those cells
 
Upvote 0
Always paste in A1:I1?

You did not answer that question.

If it is cell A then use the following macro. But if you should paste into the next available row then use the test2 macro at the end of this post.

VBA Code:
Sub test()
  Dim IE As Object, i As Long
  For i = 1 To 10
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate Range("T" & i).Value
    Do
      If IE.ReadyState = 4 Then
        IE.Visible = False
        Exit Do
      Else
        DoEvents
      End If
    Loop
    
    'Wait for window to open!
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.Visible = True
    IE.ExecWB 17, 0 '// SelectAll
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.ExecWB 12, 2 '// Copy selection
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.Quit
    ' End With
    Set IE = Nothing
    Application.Wait (Now + TimeValue("0:00:01"))
    Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, _
    DisplayAsIcon:=False
    Application.CutCopyMode = False
  Next
End Sub

__________________________________________________________________________
VBA Code:
Sub test2()
  Dim IE As Object, i As Long
  For i = 1 To 10
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate Range("T" & i).Value
    Do
      If IE.ReadyState = 4 Then
        IE.Visible = False
        Exit Do
      Else
        DoEvents
      End If
    Loop
    
    'Wait for window to open!
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.Visible = True
    IE.ExecWB 17, 0 '// SelectAll
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.ExecWB 12, 2 '// Copy selection
    Application.Wait (Now + TimeValue("0:00:01"))
    IE.Quit
    ' End With
    Set IE = Nothing
    Application.Wait (Now + TimeValue("0:00:01"))
    Range("A" & Rows.Count).End(xlUp)(2).Select
    ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, _
    DisplayAsIcon:=False
    Application.CutCopyMode = False
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,959
Latest member
camelliaCase

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