Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Update Value on Web Page via Excel Macro

  1. #1
    New Member
    Join Date
    Feb 2013
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Update Value on Web Page via Excel Macro

    Hello


    I have been fighting with a problem for a while with no success.


    I want to update a field on a webpage via excel vba.


    I am using IE11.


    Below is a picture of the source code of the page in question.


    I want to update the Value from 29 to 31 for example.


    I have tried getelementsby ID or tagname none of which works.


    Can anyone help?


    Thank you

    <input class="form-control" id="Input_Value" onblur="showUpdateModalCalcTotal(0)" type="text" value="29.00">

    <xxxinput class="form-control" id="Input_Value" onblur="showUpdateModalCalcTotal(0)" type="text" value="29.00" xxx="">

    input class="form-control" id="Input_Value" onblur="showUpdateModalCalcTotal(0)" type="text" value="29.00"</xxxinput>
    Last edited by Mark123456789; Jun 1st, 2019 at 09:37 AM. Reason: to add image

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,722
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Try...

    Code:
    HTMLDoc.getElementById("Input_Value").value = "31"
    ...where HTMLDoc is an object variable that has been assigned the HTML document from Internet Explorer.

    Hope this helps!

  3. #3
    New Member
    Join Date
    Feb 2013
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Quote Originally Posted by Domenic View Post
    Try...

    Code:
    HTMLDoc.getElementById("Input_Value").value = "31"
    ...where HTMLDoc is an object variable that has been assigned the HTML document from Internet Explorer.

    Hope this helps!

    Thanks for the reply.

    I am still having trouble, the code i have so far is:-

    Sub visboard()


    Dim IE As Object
    Dim HTMLDoc As Object


    Set IE = CreateObject("InternetExplorer.Application")


    IE.Visible = True
    IE.Navigate "https:xxxxxxxxxxxxxxxx"


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


    HTMLDoc.getElementById("Input_Value").Value = "31"


    End Sub

  4. #4
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,722
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    After the page is finished loading, you need to assign the html document to HTMLDoc. And, you should also check the ready state. Try...

    Code:
    Sub visboard()
    
        Dim IE As Object
        Dim HTMLDoc As Object
        
        Const READYSTATE_COMPLETE As Long = 4
        
        Set IE = CreateObject("InternetExplorer.Application")
        
        With IE
            .Visible = True
            .navigate "https://www.google.com"
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set HTMLDoc = IE.document
        
        HTMLDoc.getElementById("Input_Value").Value = "31"
        
        Set IE = Nothing
        Set HTMLDoc = Nothing
        
    End Sub
    Hope this helps!

  5. #5
    New Member
    Join Date
    Feb 2013
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Quote Originally Posted by Domenic View Post
    After the page is finished loading, you need to assign the html document to HTMLDoc. And, you should also check the ready state. Try...

    Code:
    Sub visboard()
    
        Dim IE As Object
        Dim HTMLDoc As Object
        
        Const READYSTATE_COMPLETE As Long = 4
        
        Set IE = CreateObject("InternetExplorer.Application")
        
        With IE
            .Visible = True
            .navigate "https://www.google.com"
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set HTMLDoc = IE.document
        
        HTMLDoc.getElementById("Input_Value").Value = "31"
        
        Set IE = Nothing
        Set HTMLDoc = Nothing
        
    End Sub
    Hope this helps!
    Hi Domenic

    Your solution does work which i am grateful and appreciate your support.

    However the website in question is a bit complicated. The website i want to update involves the following:-

    1) Open the Website URL address

    2) The website has a series of buttons (9 in total). The HTML code for two of the buttons is shown below:-:-

    XXX button *******="showUpdateModal(0)">Update</button XXX


    XXX button *******="showUpdateModal(1)">Update</button XXX

    3) I need to press one of buttons which opens up a menu box where i need to update the value from 29 to 31. The HTML code for the box i wish to update is as follows:-


    XXX input class="form-control" id="Input_Value" onblur="showUpdateModalCalcTotal(0)" type="text" value="29.00" XXX - The code you supplied does work to update this box.

    4) I then need to press another button to saves the changes.


    Is there anyway of automatically pressing the initial button so that the menu box opens allowing me to update the value?

    If there is then i can do the rest through copying and pasting.

    It is pressing this button where i cam getting stuck.

    Thanks

  6. #6
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,722
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Can you provide the URL address?

  7. #7
    New Member
    Join Date
    Feb 2013
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Quote Originally Posted by Domenic View Post
    Can you provide the URL address?
    Hi Domenic

    I which i could i cannot, i am unable to give it away - which is making the whole thing more difficult to solve.

    Do i cannot even send you screen shots.

    Do you have an email address i can send you some pictures of what i am referring to?

    I think i can solve most of the problem, the bit i am struggling with is how do i automatically click a button? that is the bit i', struggling with?


    I cannot use the getelement Name or Tag to press a button, the HTML code for the specific button is shown below.

    What vba code can i use to press the button that is encoded with the following HTML:-

    xxx button o n c l i c k ="showUpdateModal(0)">Update</button xxx

    (replace xxx with < and >)
    Last edited by Mark123456789; Jun 2nd, 2019 at 01:06 PM.

  8. #8
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,722
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Try the following code...

    HTML Code:
    HTMLDoc.querySelector("button[o n c l i c k='showUpdateModal(0)']").click
    Does this help?

  9. #9
    New Member
    Join Date
    Feb 2013
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Domenic

    You are a star - I had to alter a few bits but it works.

    Thank you so much.

    Let me know if i can do anything for you.

    You really have helped me out a lot.

    Thanks mate.

  10. #10
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,722
    Post Thanks / Like
    Mentioned
    29 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Update Value on Web Page via Excel Macro

    Mark, your thanks is more than enough. I'm glad I could help.

    Cheers!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •