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:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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!
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0
Try the following code...

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

Does this help?
 
Upvote 0
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.
 
Upvote 0
Mark, your thanks is more than enough. I'm glad I could help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top