# Update Value on Web Page via Excel Macro



## Mark123456789 (Jun 1, 2019)

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>


----------



## Domenic (Jun 1, 2019)

Try...


```
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 (Jun 1, 2019)

Domenic said:


> Try...
> 
> 
> ```
> ...




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 (Jun 1, 2019)

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


```
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 (Jun 2, 2019)

Domenic said:


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



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


----------



## Domenic (Jun 2, 2019)

Can you provide the URL address?


----------



## Mark123456789 (Jun 2, 2019)

Domenic said:


> 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 >)


----------



## Domenic (Jun 2, 2019)

Try the following code...


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

Does this help?


----------



## Mark123456789 (Jun 2, 2019)

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 (Jun 2, 2019)

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

Cheers!


----------



## Mark123456789 (Jun 1, 2019)

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>


----------



## Mark123456789 (Jun 8, 2019)

Hi Domenic

I was hoping I could pick your brain again if you had some time.

I am trying to get some information from an internal intranet webpage.

I use a bit of vba code to load the page (listed below).

To get the information, I need to click a link which opens a list tree on the left side of the same page.

I then click an item on the tree list which expands to several sub items.

From this sub list of items, I need to extract a value.

Since all the data is on the same page I thought I could somehow extract the value I’m interested in directly – but I’m, struggling.

The HTML code behind the value I need is as follow:-

Xxx div style="cursor: pointer;" *******="OpenPage('_faultlist.aspx?guid=1&mode=teams&id=WWE410&value=P+B+R', 'iframe2');">PBR (4,0) xxxx

(Replace Xxx with < and replace xxxx </div>)

I need to extract the value 4 from PBR (4,0).

I am struggling.

I thought I could use the getelement by Name/ID/Tag but no luck?

Do you think you shed any light?

Thank you.




Code to open website:-

 Sub Test()
 Dim IEapp As Object
 Dim WebUrl As String


 Set IEapp = CreateObject("InternetExplorer.Application") 'Set IEapp = InternetExplorer
 WebUrl = "http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

 With IEapp
 .Silent = True 'No Pop-ups
 .Visible = True 'Set InternetExplorer to Visible
 .Navigate WebUrl 'Load web page
 End With

 End Sub


----------



## Domenic (Jun 8, 2019)

Can you post an image of the relevant portion of the source code?


----------

