+ Reply to Thread
Results 1 to 2 of 2

VBA HTML Get element by Div ID

  1. #1
    Registered User
    Join Date
    10-14-2020
    Location
    Dublin
    MS-Off Ver
    Professional plus
    Posts
    44

    VBA HTML Get element by Div ID

    I wrote the following script which simply copies excel data and fills a form:

    Sub Autofill()


    Dim IE As Object

    Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")

    IE.Visible = True
    IE.navigate "https://share.amazon.com/sites/IPV/Lists/IPV%20Appeals%20tracker/Issue/newifs.aspx?Source=https%3A%2F%2Fshare%2Eamazon%2Ecom%2Fsites%2FIPV%2FLists%2FIPV%2520Appeals%2520tracker%2FFiltered%2520Audits%2Easpx%23InplviewHashdef098f9%2Dcf4e%2D4a1f%2Dbe97%2D76d526f992a1%3D&RootFolder="

    Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
    Loop

    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T9").Value = ThisWorkbook.Sheets("Audits").Range("AO12") '*** tag
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T8").Value = ThisWorkbook.Sheets("Audits").Range("AM12") 'man tag
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T1").Value = ThisWorkbook.Sheets("Audits").Range("AC12") 'Task ID
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T2").Value = ThisWorkbook.Sheets("Audits").Range("F12") 'mcid
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T5").Value = ThisWorkbook.Sheets("Audits").Range("C12") 'country
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T19").Value = ThisWorkbook.Sheets("Audits").Range("AH12") 'type of audit
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T3").Value = ThisWorkbook.Sheets("Audits").Range("AL12") 'site
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T4").Value = ThisWorkbook.Sheets("Audits").Range("AN12") 'Marketplace
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T6").Value = ThisWorkbook.Sheets("Audits").Range("AD12") 'time
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T10").Value = ThisWorkbook.Sheets("Audits").Range("K12") '*** act
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T11").Value = ThisWorkbook.Sheets("Audits").Range("L12") 'corr act
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_RTC60_RTI1_RT1_newRichText").Value = ThisWorkbook.Sheets("Audits").Range("P12") ' QA Comment
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T12").Value = ThisWorkbook.Sheets("Audits").Range("U12") 'siv act
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T13").Value = ThisWorkbook.Sheets("Audits").Range("V12") ' cor siv act -------------
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_T17").Value = ThisWorkbook.Sheets("Audits").Range("Q12") 'metric name
    ' IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_D14").Value = ThisWorkbook.Sheets("Audits").Range("X12") 'siv rfd reason
    ' IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_D15").Value = ThisWorkbook.Sheets("Audits").Range("AI12") 'data correctly capt
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_D15").Value = ThisWorkbook.Sheets("Audits").Range("AA12") 'if correctly cap
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_D62").Value = "No"
    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_RTC60_RTI1_RT1_newRichText").InnerHtml = ThisWorkbook.Sheets("Audits").Range("P12") 'annot

    End Sub

    everything works except for one field which is the only comment box:

    IE.document.getElementByID("ctl00_ctl33_g_5ff91550_e03b_4237_b657_15a2e453904d_FormControl0_V1_I1_RTC60_RTI1_RT1_newRichText").Value = ThisWorkbook.Sheets("Audits").Range("P12") ' QA Comment

    All the other HTML elements look have an input ID.

    But that comment box doesnt have an input ID but has a DIV ID.

    I tried using the GetElementByTagName or setting it as InnerHtml instead of Value, but doesnt work.

    If you could help me out, id be greatful!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,703

    Re: VBA HTML Get element by Div ID

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. [SOLVED] Error on VBA code for pull or extract data from HTML Element in Excel
    By rayhee1985 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-16-2020, 04:50 AM
  2. How can i delete HTML element in vba excel ?
    By John_999 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2020, 03:00 PM
  3. How to select webpage HTML Input element list item
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-09-2017, 02:43 PM
  4. Import data from specific HTML element based URLs in a column
    By whatever61 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2016, 08:04 AM
  5. Cannot find username element Id in fedex.com/us html code.
    By Locrian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2015, 02:53 PM
  6. NEED HELP: How to code correctly an HTML element to excel vba
    By blackorchids2002 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2015, 04:15 PM
  7. [SOLVED] Parsing HTML element into excel
    By chococ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2014, 05:20 PM

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