Consulting

Results 1 to 8 of 8

Thread: Copy content of Several Webpages

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Exclamation Copy content of Several Webpages

    IHi
    I have thsi VBA code that can copy http://www.website.com/home/ and paste in excel now my question is i need to copy several page with different url
    Like :
    http://www.website.com/home/
    copy above url and do run some code and again next url
    http://www.website.com/Data2/
    copy above url and do run some code and again next url
    http://www.website.com/Apple/
    copy above url and do run some code and again next url
    http://www.domian.com/BoB/

    Hope you will understand

    Sub webCopier()
    Dim lnk As Object, ie As Object, doc As Object, i As Long, R As Range, fAdr As String, nR As Long, cutRng As Range, Ar As Range, delAdr As String, LR As Long
     Set ie = CreateObject("InternetExplorer.Application")
     With ie
     .Visible = True
     .navigate "http://www.website.com/home/"
     
     Do Until .readyState = 4: DoEvents: Loop
     Application.wait (Now() + TimeValue("00:00:5"))
     Set doc = ie.document
     .ExecWB 17, 0 '// SelectAll
     .ExecWB 12, 2 '// Copy selection
     .Quit
     End With
     Set ie = Nothing
     Range("A1").Select
     ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
     DisplayAsIcon:=False
    
    'Some of my code will be place here. 
    End Sub

  2. #2
    Something like:

    Sub Demo()
        WebCopier "http://www.website.com/home/"
        WebCopier "http://www.website.com/home/"
        WebCopier "http://www.website.com/Data2/"
        WebCopier "http://www.website.com/Apple/"
        WebCopier "http://www.domian.com/BoB/"
    End Sub
    
    Sub webCopier(sURL As String) 
        Dim lnk As Object, ie As Object, doc As Object, i As Long, R As Range, fAdr As String, nR As Long, cutRng As Range, Ar As Range, delAdr As String, LR As Long 
        Set ie = CreateObject("InternetExplorer.Application") 
        With ie 
            .Visible = True 
            .navigate sURL 
             
            Do Until .readyState = 4: DoEvents: Loop 
                Application.wait (Now() + TimeValue("00:00:5")) 
                Set doc = ie.document 
                .ExecWB 17, 0 '// SelectAll
                .ExecWB 12, 2 '// Copy selection
                .Quit 
            End With 
            Set ie = Nothing 
            Range("A1").Select 
            ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _ 
            DisplayAsIcon:=False 
             
             'Some of my code will be place here.
        End Sub

  3. #3
    Something like:

    Sub Demo()
        WebCopier "http://www.website.com/home/"
        WebCopier "http://www.website.com/home/"
        WebCopier "http://www.website.com/Data2/"
        WebCopier "http://www.website.com/Apple/"
        WebCopier http://www.domian.com/BoB/
    End Sub
    
    Sub webCopier(sURL As String)
        Dim lnk As Object, ie As Object, doc As Object, i As Long, R As Range, fAdr As String, nR As Long, cutRng As Range, Ar As Range, delAdr As String, LR As Long
        Set ie = CreateObject("InternetExplorer.Application")
        With ie
            .Visible = True
            .navigate sURL
            
            Do Until .readyState = 4: DoEvents: Loop
                Application.wait (Now() + TimeValue("00:00:5"))
                Set doc = ie.document
                .ExecWB 17, 0 '// SelectAll
                .ExecWB 12, 2 '// Copy selection
                .Quit
            End With
            Set ie = Nothing
            Range("A1").Select
            ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
            DisplayAsIcon:=False
            
            'Some of my code will be place here.
        End Sub
    Last edited by Jan Karel Pieterse; 10-30-2013 at 03:46 AM.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Hi Jan.how about adding a worksheet/range parameter to sub where web contents will be pasted.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    You mean like so:

     Sub Demo()
         WebCopier "http://www.website.com/home/", Worksheets("Sheet2").Range("A2")
         WebCopier "http://www.website.com/home/", Worksheets("Sheet2").Range("B2")
         WebCopier "http://www.website.com/Data2/", Worksheets("Sheet2").Range("C2")
         WebCopier "http://www.website.com/Apple/", Worksheets("Sheet2").Range("D2")
         WebCopier "http://www.domian.com/BoB/", Worksheets("Sheet2").Range("E2")
     End Sub
    
     Sub webCopier(sURL As String, oDestination As Range)
         Dim lnk As Object, ie As Object, doc As Object, i As Long, R As Range, fAdr As String, nR As Long, cutRng As Range, Ar As Range, delAdr As String, LR As Long
         Set ie = CreateObject("InternetExplorer.Application")
         With ie
             .Visible = True
             .navigate sURL
             
             Do Until .readyState = 4: DoEvents: Loop
                 Application.wait (Now() + TimeValue("00:00:5"))
                 Set doc = ie.document
                 .ExecWB 17, 0 '// SelectAll
                 .ExecWB 12, 2 '// Copy selection
                 .Quit
             End With
             Set ie = Nothing
             Application.Goto oDestination
             ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
             DisplayAsIcon:=False
             
             'Some of my code will be place here.
         End Sub
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  6. #6
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    It was my mistake and your code 100% work . Thank you very much .
    Last edited by parscon; 10-30-2013 at 04:11 AM.

  7. #7
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I found the problem just i must add Worksheets("Sheet1").Activate to end of my code .

    Thank you very much . Really you save me .

    Best Regards

  8. #8
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by Jan Karel Pieterse View Post
    You mean like so:
    exactly.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •