Results 1 to 6 of 6
  1. #1
    dupes is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    4

    Smile Web to access table

    Hello Friends,


    I am trying to save the sheet from following page to an access table
    Any ideas on how to achieve this?

    Web Page: https://docs.google.com/spreadsheets...=0&single=true

    I am able to download it to a Text box "Text3 " using following code but is there a way to get the sheet as a table?



    Dim IE As Object
    Set IE = CreateObject("Internetexplorer.Application")


    IE.Visible = False
    IE.NAVIGATE "https://docs.google.com/spreadsheets/d/e/2PACX-1vTeVs6qiVE6YQ1MUeK_9NHa-URkdR7D6KEr4y6Sj-EtQuyBRf-3s7rfSI0iO3mzgUut6pwBxi-3chO9/pubhtml?gid=0&single=true"
    Do While IE.BUSY Or IE.READYSTATE <> 4


    Loop


    Dim PAGE As String
    Dim PG1() As String


    PAGE = IE.Document.BODY.INNERTEXT


    Me.Text3 = PAGE
    Refresh

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Scraping web page gets complicated. Got the following to work:
    Code:
    Sub test()
    Dim htm As Object
    Dim Tr As Object
    Dim Td As Object
    Dim Tab1 As Object
    Dim Web_URL As String
    Dim ie As Object
    Dim iTable As Integer'Replace the URL of the webpage that you want to download
    Web_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTeVs6qiVE6YQ1MUeK_9NHa-URkdR7D6KEr4y6Sj-EtQuyBRf-3s7rfSI0iO3mzgUut6pwBxi-3chO9/pubhtml?gid=0&single=true"
    'open Internet Explorer and go to website
    Set ie = New InternetExplorer
    ie.Visible = False
    ie.Navigate Web_URL
    Do While ie.ReadyState <> READYSTATE_COMPLETE
        'Application.StatusBar = "Trying to go to webpage ..."
        DoEvents
    Loop
    'Create HTMLFile Object
    Set htm = ie.Document
    Set ie = Nothing
    'Loop through each table
    For Each Tab1 In htm.getElementsByTagName("table")
        With htm.getElementsByTagName("table")(iTable)
            For Each Tr In .Rows
                For Each Td In Tr.Cells
                    If Td.ClassName Like "S*" Then
                       CurrentDb.Execute "INSERT INTO Table1(WebTest) VALUES('" & Td.innertext & "')"
                    End If
                Next Td
            Next Tr
        End With
        iTable = iTable + 1
    Next Tab1
    End Sub
    Alternative is to use Excel's Get External Data to import from web page. That worked very nicely. AFAIK, equivalent is not available in Access.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dupes is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    4
    Thanks,
    U are rite

    Is there a way to download the web page as html then using VBA and then use a Get external data to fetch the content?
    I was trying this unfortunately couldnt get through to save it to a local drive

  4. #4
    dupes is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    4

    Post

    Managed to get it in a better way
    brought in the data in a csv format into a text box with ";" and then appended it to a table, "&output=csv" made the difference in the url

    URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTeVs6qiVE6YQ1MUeK_9NHa-URkdR7D6KEr4y6Sj-EtQuyBRf-3s7rfSI0iO3mzgUut6pwBxi-3chO9/pub?gid=0&single=true&output=csv"
    Set HTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    HTTP.Open "GET", URL, False
    HTTP.Send
    CSV = HTTP.ResponseText
    DataRows = Split(CSV, Chr(10)) ' split the CSV into rows
    Me.Text3 = CSV


    Refresh

    Thanks for your help

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Wow, that is nice! And fast! Glad you got it figured out.

    Guessing don't need to do conventional web page scraping because of the data source.
    Last edited by June7; 10-21-2018 at 01:54 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    @Dupes
    For info, the approach you used can also be very easily adapted for importing XML or JSON files if needed
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export Filtered table to Excel, Edit and Re-Import Changes to Access Table
    By Access_throwaway in forum Import/Export Data
    Replies: 15
    Last Post: 02-20-2018, 12:37 PM
  2. Replies: 13
    Last Post: 05-15-2013, 09:52 AM
  3. Replies: 2
    Last Post: 10-09-2012, 03:20 PM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums