+ Reply to Thread
Results 1 to 9 of 9

Download Excel Workbook from IE copy and paste into existing Workbook

Hybrid View

kboy1289 Download Excel Workbook from... 12-16-2013, 01:12 PM
kboy1289 Re: Download Excel Workbook... 12-16-2013, 01:53 PM
Leith Ross Re: Download Excel Workbook... 12-16-2013, 02:13 PM
kboy1289 Re: Download Excel Workbook... 12-16-2013, 02:26 PM
Leith Ross Re: Download Excel Workbook... 12-16-2013, 02:31 PM
kboy1289 Re: Download Excel Workbook... 12-16-2013, 02:39 PM
Marc L Re: Download Excel Workbook... 12-16-2013, 02:59 PM
Leith Ross Re: Download Excel Workbook... 12-16-2013, 03:10 PM
kboy1289 Re: Download Excel Workbook... 12-16-2013, 03:13 PM
  1. #1
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Download Excel Workbook from IE copy and paste into existing Workbook

    Hi all,
    i'm attempting to use VBA to have internet explorer open, navigate to a website open the excel workbook copy & paste the sheet into an existing open workbook (essentially replacing all data with most recent data) and close the workbook (the one from which data is coming from) i've gotten to the point where i have the option to open/save/cancel the download but not sure where to go from there. i've also attached the workbook that i want it to go in. basically just copy and paste into "Rate" worksheet overwriting previous data.

    any help is appreciated!

    Sub APORTable()
       
    
        Dim oIE As InternetExplorer
        Dim oExcel As Excel.Application
    
        Set oIE = CreateObject("InternetExplorer.Application")
        oIE.Navigate ("http://www.ffiec.gov/ratespread/YieldTableFixed.CSV")
        
        Do While oIE.Busy: DoEvents: Loop
        Do While oIE.readyState <> 4: DoEvents: Loop
        
        oIE.Visible = True
        
    End Sub
    Attached Files Attached Files
    Last edited by kboy1289; 12-16-2013 at 01:52 PM.

  2. #2
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    updated the workbook to include the necessary references and added a little more to the code i had.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    Hello kboy1289,

    Here is faster an easier way to it.
    Sub ImportCSVFromWeb(ByVal URL As String)
    
        ' Summary: Imports a CSV file from the web to tthe active worksheet.
        ' Written: December 16, 2013
        ' Author:  Leith Ross
        
        Dim i As Long
        Dim n As Long
        Dim r As Long
        Dim Text As String
        Dim TextLine As String
        Dim TextArray As Variant
        
            With CreateObject("MSXML2.XMLHTTP")
                .Open "GET", URL, True
                .send
                While .readyState <> 4: DoEvents: Wend
                Text = .responsetext
            End With
            
            Text = GetServerResponse(URL)
            
            Do
                i = n + 1
                n = InStr(i, Text, Chr(10))
                If n = 0 Then Exit Do
                
                TextLine = Mid(Text, i, n - i)
                
                If InStr(1, TextLine, ",") Then
                    TextArray = Split(TextLine, ",")
                    Range("A1").Offset(r, 0).Resize(1, UBound(TextArray)).Value = TextArray
                Else
                    Range("A1").Offset(r, 0).Value = TextLine
                End If
                
                r = r + 1
            Loop
                
    End Sub
    
    Sub GetYieldTable()
    
        Call ImportCSVFromWeb("http://www.ffiec.gov/ratespread/YieldTableFixed.CSV")
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    hello leith,
    it looks like its failing at the "Text = GetServerResponse(URL)" line am i changing anything or defining anything? or adding a reference?
    thanks!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    Hello kboy1289,

    Did you run the macro GetYieldTable first?

    Did you receive an error message?

  6. #6
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    yes when i ran the GetYieldTable it came back with a compile error: Sub or Function not defined.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Download Excel Workbook from IE copy and paste into existing Workbook


    Hi,

    a direct opening file is doable ‼
    Sub Demo()
        Workbooks.Open "http://www.ffiec.gov/ratespread/YieldTableFixed.CSV", Format:=2
    End Sub

    As a direct reading in an array variable …

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    @ Marc L,

    Nice solution. I had forgotten "Workbook.Open" would take a URL as a valid file option.

  9. #9
    Registered User
    Join Date
    02-01-2011
    Location
    Philadelphia, Pennsylvania
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Download Excel Workbook from IE copy and paste into existing Workbook

    very nice marc! thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy column based on partial word match in first row and paste into existing workbook
    By David Harris 1987 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2013, 03:52 PM
  2. Copy column based on partial word match in first row and paste into existing workbook
    By David Harris 1987 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2013, 01:02 PM
  3. how to copy excel sheet from one workbook and paste into another workbook, save it ?
    By dearnemo385 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2012, 08:27 AM
  4. Excel: match, vlookup in other workbook, copy and paste in old workbook.
    By BeefGir in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2012, 01:26 PM
  5. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1