Results 1 to 8 of 8

Macro works only when viewing the source code

Threaded View

  1. #1
    Registered User
    Join Date
    09-19-2016
    Location
    Prague
    MS-Off Ver
    13
    Posts
    4

    Macro works only when viewing the source code

    Hello, I have following issue:
    I try to pull some data from html table using a code below. Just to explain - It is web where I need to put some values into forms and press enter to generate a html table.

    My code works just fine BUT only when I go to "View Code" and run the macro from there. When I run the macro via button or from Developer tab, it DOES NOT work well. Basically what it does is it intputs only the first row from html table instead of its full content (cca 14 rows). What really confuses me is, that when I run the macro from "View Code" for the first time a then run again via button suddenly it works just fine. This happens till I close the whole workbook, when I open it again I have to run the macro from the "View Code" again...

    My code is located in Module1. Is that an issue? Do you have any idea what am I doing wrong.
    Thanks

    My code:

    Sub Download()
    
    Dim IE As Object
    Dim hTable As Object
    Dim hBody As Object
    Dim hTR As Object
    
    Dim htD As Object
    Dim tb As Object
    Dim tr As Object
    Dim td As Object
       
    Start = Day(Date - 20) & "." & Month(Date - 20) & "." & Year(Date - 20)
    Ending = Day(Date) & "." & Month(Date) & "." & Year(Date)
    
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate " 'Web site from which I am dowloading data' "
    
    Do Until IE.readyState = 4
    Loop
    
    IE.document.all("txtDateFrom").Value = Start
    IE.document.all("txtDateTo").Value = Ending
    IE.document.all("txtDateTo").Select
    SendKeys "{ENTER}", True
    SendKeys "{NUMLOCK}", True
    
    Application.Wait (Now + TimeValue("00:00:01"))
    
    Set hTable = IE.document.getElementsByTagName("table")
        For Each tb In hTable
        Set hTR = IE.document.getElementsByTagName("tr")
            For Each tr In hTR
            Set htD = tr.getElementsByTagName("td")
            y = 1
                For Each td In htD
                Cells(x, y) = td.innerText
                y = y + 1
                Next td
            x = x + 1
            Next tr
        Exit For
    Next tb
    IE.Quit
    
    End Sub
    Last edited by LePetit11; 09-19-2016 at 11:00 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2015, 09:06 AM
  2. [SOLVED] Add code to a macro for the purpose of unlocking a project for viewing
    By ekr in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-24-2013, 03:34 PM
  3. Replies: 0
    Last Post: 06-02-2012, 10:11 AM
  4. Dynamic combo row source - works only if active source worksheet
    By fredpox in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-21-2010, 07:16 AM
  5. Viewing source of a pivot table
    By hbear in forum Excel General
    Replies: 3
    Last Post: 08-02-2006, 06:25 PM
  6. Works as Macro but not in code
    By SueJB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2005, 06:45 PM
  7. [SOLVED] Viewing source code when saved as web page
    By Mark in forum Excel General
    Replies: 1
    Last Post: 03-31-2005, 02:06 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