Update Value on Web Page via Excel Macro

Mark123456789

New Member
Joined
Feb 23, 2013
Messages
14
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:

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,169
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!
 

Mark123456789

New Member
Joined
Feb 23, 2013
Messages
14
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
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,169
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!
 

Mark123456789

New Member
Joined
Feb 23, 2013
Messages
14
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
 

Mark123456789

New Member
Joined
Feb 23, 2013
Messages
14
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:

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,169
Try the following code...

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

Mark123456789

New Member
Joined
Feb 23, 2013
Messages
14
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.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,169
Mark, your thanks is more than enough. I'm glad I could help.

Cheers!
 

Watch MrExcel Video

Forum statistics

Threads
1,099,252
Messages
5,467,550
Members
406,544
Latest member
semoredhawk

This Week's Hot Topics

Top