Consulting

Results 1 to 5 of 5

Thread: Check if a text box exists in a webpage and if so then run code.

  1. #1

    Check if a text box exists in a webpage and if so then run code.

    Having issues with several of the vendors i work for. They have a web form that i complete by transferring data from excel into there webpage. This vendor has several web forms that look similar but have additional questions(text boxes) that differ from form to form and need filling out.
    What i want to do is check/test if webpage hold that text box and if so then run my code.


    Sample web code for a text box i want to check for on a web page and if it exist on web page then run the code below:
    [vba]<input name="ext_color" class="textfield required" id="ext_color" type="text" maxlength="15" value="Baige">[/vba]

    This is how i input data into this text box:
    [vba]IE.Document.getElementsByName("ext_color")(0).Value = Range("aj54")[/vba]

    What normally happens is this text box is not on all forms that i complete, so i want to eliminate/bypass executing the code by implementing an If..Then statement for when the text box is not included on the webpage form.


    thanks in advance.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Do you know what the text box is called, or is it the only one on the web page?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Quote Originally Posted by Aussiebear View Post
    Do you know what the text box is called, or is it the only one on the web page?
    This code holds the text box:
    [vba]<input name="ext_color" class="textfield required" id="ext_color" type="text" maxlength="15" value="Baige">[/vba]

    name="ext_color" is the text box



  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    below may give you an idea:

    Dim txtColor As Object
    On Error Resume Next
    Set txtColor = IE.Document.getElementsByName("ext_color")
    If Not txtColor Is Nothing Then
        txtColor.Value = Range("AJ54")
    End If
    On Error GoTo 0
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    or

    On Error Resume Next 
    IE.Document.getElementsByName("ext_color").Value=Range("AJ54")

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
  •