+ Reply to Thread
Results 1 to 8 of 8

Macro works only when viewing the source code

  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:

    Please Login or Register  to view this content.
    Last edited by LePetit11; 09-19-2016 at 11:00 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro works only when viewing the source code

    Well, if you run it now, you will get an error as today's date can not be negative.
    Start = Day(Date - 20) & "." & Month(Date - 20) & "." & Year(Date - 20)
    You are also using send keys which are not reliable and do not even use them.
    Is the site private, i.e. can you post the URL?


    Please Login or Register  to view this content.

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

    Re: Macro works only when viewing the source code

    Hi, thanks: here is the URL: "https://www.conseq.cz/indexes/IndexCZGBFRN.aspx"
    I am not sure if there is a problem with dates...but I would like to put two dates into forms on the web site.

    Start ...lets say 20 days before today (30.8.2016)
    End....today

    Well I have no clue how to go around sendkeys in this particular case...
    Because when I go the website, you have to press enter, to make a table generate, with the sendkeys I have tried to do this step...
    Last edited by LePetit11; 09-19-2016 at 11:26 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro works only when viewing the source code

    Okay, this works, but you need to be careful with your dates. They are actually not dates, but strings. The out put data are in sheet1, but you can change it to suit you.

    Please Login or Register  to view this content.

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

    Re: Macro works only when viewing the source code

    Thank you for the code, however I have still the same issue, when I call it via button in other Sheet, I still receive only the first row of the table, when I call it from "View code" it works well. Once it downloads the whole table, button works fine too. Could be there an issue in SendKeys method ? Is there a different method to use and "press enter" and send the input on the web page?

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro works only when viewing the source code

    Your code errors as you have not given the initial value of x- it is none on the first loop. Initially, I did not notice it. Having correcting it, however, the code still picks up ONLY the first 4 rows. I do not think it is the key issue- more likely to a restriction on the site. I have tried a different method and got the same result as your code. Chrome will not allow you to the see the view code. I suspect the site might have some kind of restriction.

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

    Re: Macro works only when viewing the source code

    I am using Internet explorer if that matters. I am just wondering, it seems like the Excel has to "see" there is a real user who is actually clicking on View code and then allows to run macro properly. Interesting is when I open the Excel, just click on view code and then Run the macro via button - it works FINE. Seems to me there is maybe some issues in Excel setting rather than website, but honestly I have no clue. Thanks a lot anyway

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro works only when viewing the source code

    I am not entirely sure, but I suspect the summation is handled by JavaScript. That is the reason for not seeing any summit button to click. I believe this is done on purpose to avoid multiple session; it is like the kopcha. The default value you get is today's date, even if your dates input are wrong. When you manually directly input the data on the site, you get all the entries. When you do enter the dates through a code, the site is assuming as if your input data are wrong and therefore you get default value , which is a single row of today's date.
    I do not know how you are getting all the data through pressing a button. When I run the code using F8, I get only a single row.

+ 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. 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