mardi 27 juillet 2021

VBA to open webpage then submit data

I am very new to IE controlled by vba, but have stumbled by to write the following code, which was pieced together using various online searches.

My issue is that while this code works if a breakpoint is added before the 'click/submit' is clicked (then going to the IE window), it does not seem to update the webpage when it is run without a breakpoint.

If I were to break the code and see where the cursor is on the webpage, then resume the code, it will save and update but i can't seem to get it working normally.

Any help is much appreciated.

Sub test()
url = "Sharepoint - hidden"

Set IE = New InternetExplorerMedium
    IE.Visible = True
    IE.Navigate url
    
    
Dim HTMLDOC As HTMLDocument

Dim MyHTML_Element As IHTMLElement
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE

Set HTMLDOC = IE.Document


HTMLDOC.all.Item("ctl00_ctl40_g_07433f93_b974_4a29_9e53_cc3a087aa20a_FormControl0_V1_I1_T5").innerText = "New Employee - Test:" & Now()   '[Request Type]
HTMLDOC.all.Item("ctl00_ctl40_g_07433f93_b974_4a29_9e53_cc3a087aa20a_FormControl0_V1_I1_T5").Focus
HTMLDOC.all.Item("ctl00_ctl40_g_07433f93_b974_4a29_9e53_cc3a087aa20a_FormControl0_V1_I1_B3").Click
End sub



Aucun commentaire:

Enregistrer un commentaire