+ Reply to Thread
Results 1 to 31 of 31

VBA need to input yesterdays date in a field in IE11

  1. #1
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Question VBA need to input yesterdays date in a field in IE11

    Hello Gurus,

    I am trying to input yesterdays date in a field in IE. My code currently gets me to the page, and I need to have it always enter the previous date in the cell to generate the report I will be pulling to Excel.

    Any ideas on how I can do this? I have already tried

    Please Login or Register  to view this content.
    But this is not working.

    Thanks,
    John
    Last edited by Johnnyv015; 10-02-2014 at 02:41 PM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA need to input yesterdays date in a field in IE11

    Hi John,

    Try something like:
    Please Login or Register  to view this content.
    Change the contents of the format statement to suit your web site requirements.

    Lewis

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA need to input yesterdays date in a field in IE11

    Basic example, of course you can change the date formatting to whatever you want:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Quote Originally Posted by LJMetzger View Post
    Hi John,

    Try something like:
    Please Login or Register  to view this content.
    Change the contents of the format statement to suit your web site requirements.

    Lewis
    This is not working, I'm getting run time error 424.

    I have noticed the HTML for the box I am trying to enter this into is name = "ex1-inputE1" and the code is adding a space between ex1 and - so in code it is reading "ex1 -inputE1"

    Think this is my problem?
    Last edited by Johnnyv015; 09-19-2014 at 02:59 PM.

  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: VBA need to input yesterdays date in a field in IE11

    Hello Johnnyv150,

    Can you post the HTML source code? You can copy it to Notepad and then post the text file. If is to large to post, zip it and repost.
    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!)

  6. #6
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    HTML Code: 
    This is the code for the box I am trying to enter this in.

  7. #7
    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: VBA need to input yesterdays date in a field in IE11

    Hello Johnnyv150,

    this HTML Input tag is lacking the Type attribute. Every Input has a type like Button, CheckBox, Date, Text, just to name a few.

    Can you copy the full HTML source an post it for review? It would be a great help.

  8. #8
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    HTML Code: 
    I think this is the full code for this area.

  9. #9
    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: VBA need to input yesterdays date in a field in IE11

    Hello Johnnyv150,

    Not what I asked for, but does shed some light on what is going on.

    The date is in a Table Cell, not a Input object like I mentioned previously. Clicking on the cell will take you to another form that will let you input a new date.

  10. #10
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    correct, there is a table cell for selecting the date, or you can just type in the date and click a submit button under this.

    I was thinking that entering the date and clicking the button would be a lot easier than using the table.

  11. #11
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    In my playing with this Table Cell I have found that I can click on the Table and press the left arrow, this will always put me on the previous date. Enter after this will fill the box I am looking to fill with the date needed.

    Think this may be the best way to get this done?

  12. #12
    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: VBA need to input yesterdays date in a field in IE11

    Hello Johnnyv150,

    This really would be easier for me if I had the complete HTML then I would not have ask you so many questions.

    Is there some reason you are reluctant to post the entire HTML source code? This will in no way violate any privacy policies.

  13. #13
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Only reason I am reluctant to post the entire page code is, it does contain many private html links. Is there a certain piece of this code you are looking for?

  14. #14
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Code for boxes and Table Cells

    HTML Code: 
    Code for button

    HTML Code: 

  15. #15
    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: VBA need to input yesterdays date in a field in IE11

    Hello Johnnyv150,

    Thanks for that. That does answer some question. However, I still not certain if you can change the date by code.

    I have to leave for a few hours. When I get back I will post some code you can try out.

  16. #16
    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: VBA need to input yesterdays date in a field in IE11

    Hello Johhnyv150,

    Here is the promised code. You will have to adapt this to your code. This lets you select the starting and ending dates and clicks the "Get Report" button.

    After doing some testing, it seems that an Input object will default to Type "text" if the Type property is missing. Although I could not find it any HTML literature, it proved to be true through testing.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Thank You Leith Ross,

    This is not working for what I am trying to do. I have come up with the code below, as I have found that by simply clicking the calendar box and pressing the left key then enter this will ALWAYS select the previous date.

    as of now this is what I put in, but it is not working in the calendar box.


    Please Login or Register  to view this content.
    Do you know of any way to make the sendkeys function act in the calendar box?

    Thanks,
    John

  18. #18
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Note: I can select the calendar box, I am just having trouble getting VBA to act in this window when it is opened.

  19. #19
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Any ideas?

  20. #20
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Quote Originally Posted by Leith Ross View Post
    Hello Johhnyv150,

    Here is the promised code. You will have to adapt this to your code. This lets you select the starting and ending dates and clicks the "Get Report" button.

    After doing some testing, it seems that an Input object will default to Type "text" if the Type property is missing. Although I could not find it any HTML literature, it proved to be true through testing.

    Please Login or Register  to view this content.
    I have tried using this code with the Input value of "Date() -1" but I am getting the runtime error 91 when entering the "With" statement.


    Any ideas on how to solve this?

    Thanks,
    John

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

    Re: VBA need to input yesterdays date in a field in IE11


    Please Login or Register  to view this content.

  22. #22
    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: VBA need to input yesterdays date in a field in IE11

    Hello John,

    The "With" statement assigns the HTML objects to VBA object variables. The date would be assigned to either"Output1" or "Output2". These are the start and ending dates respectively.

    The date must be a string in the format mm/dd/yyyy.

    For Example...
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Quote Originally Posted by Leith Ross View Post
    Hello John,

    The "With" statement assigns the HTML objects to VBA object variables. The date would be assigned to either"Output1" or "Output2". These are the start and ending dates respectively.

    The date must be a string in the format mm/dd/yyyy.

    For Example...
    Please Login or Register  to view this content.
    Thanks Leith Ross,

    I think I am missing something. I am using this.
    Please Login or Register  to view this content.
    still pulling the runtime 91 when the code gets to "With IE.document"

  24. #24
    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: VBA need to input yesterdays date in a field in IE11

    Hello John,

    Internet Explorer runs asynchronously. Which means what VBA executes is not in sync with Internet Explorer. That is why the first While loop is used.

    This keeps VBA occupied until Internet Explorer has loaded the web page. However, a loaded web an HTML document does not make. There is a certain about of time needed to convert the text into their HTML counter parts.

    It is not uncommon for the document not to have been converted by the time VBA executes the "With IE.Document" statement.

    You can add another loop to check that the document exists before proceeding like this...
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 10-01-2014 at 12:48 PM.

  25. #25
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    Quote Originally Posted by Leith Ross View Post
    Hello John,

    Internet Explorer runs asynchronously. Which means what VBA executes is not in sync with Internet Explorer. That is why the first While loop is used.

    This keeps VBA occupied until Internet Explorer has loaded the web page. However, a loaded web an HTML document does not make. There is a certain about of time needed to convert the text into their HTML counter parts.

    It is not uncommon for the document not to have been converted by the time VBA executes the "With IE.Document" statement.

    You can add another loop to check that the document exists before proceeding like this...
    Please Login or Register  to view this content.
    I have added the second loop, and I am running the whole macro through steps "F8". and I am still getting the runtime error 91 at the With Statement.

  26. #26
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    here is my full code as of now. everything is running fine up to the point we are speaking about.

    Please Login or Register  to view this content.

  27. #27
    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: VBA need to input yesterdays date in a field in IE11

    Hello John,

    Here is the corrected code. It should work now.
    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    hmmm. still got the runtime 91 object variable or With block variable not set.

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

    Re: VBA need to input yesterdays date in a field in IE11


    Do not remove Busy condition from waiting loop !

    Other tip : IE.locationName is equal to the title of the webpage only when IE finishes to load it …

  30. #30
    Registered User
    Join Date
    09-08-2014
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    55

    Re: VBA need to input yesterdays date in a field in IE11

    GOT IT!
    Thank you so much Leith Ross, you have been an amazing help on this. I ended up running the same code as above only I added a application.wait line to halt VBA for a minute while the page loaded up. Works like a champ.

    Thanks Again,
    John

  31. #31
    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: VBA need to input yesterdays date in a field in IE11

    Hello John,

    Nice work! You're welcome. Glad to know it is working for you now.

+ 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. Yesterdays date file
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2013, 03:42 AM
  2. [SOLVED] Function/formula to compare and insert todays date or yesterdays date
    By TC922 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-17-2013, 05:28 AM
  3. How to save formatted date in the input field
    By ksduded in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-20-2008, 09:44 AM
  4. [SOLVED] code an input field that asks for current date
    By jaggyone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2005, 04:00 AM

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