Auto Click Internet Explorer button in VBA (1 Viewer)

stu_c

Registered User.
Local time
Today, 00:18
Joined
Sep 20, 2007
Messages
489
Hi All
I have an IE webpage that I want to auto click a button in VBA when it automatically fills in the page, I have got the Auto fill to work just cannot work out the button click any suggestions?

Button Is called Submit in in HTML
<input type="submit" value="Save Changes" name="B1">

Set oDoc = IE.Document
'New Address
oDoc.getElementsByName("NewAddress").Item(0).Value = [Forms]![FRM_TBLALL_FullDetails].[Form]![NewAddressDetails]

oDoc.getElementsByName("Reason").Item(0).Value = "Change Of Address"


Many thanks
 

bastanu

AWF VIP
Local time
Yesterday, 16:18
Joined
Apr 13, 2010
Messages
1,402
Something like this maybe:IE.Document.all.Item("Submit").Click
And this would "click" the first button on the page (zero-based collection):
IE.Document.getElementsByTagName("button")(0).Click

Cheers,
 

stu_c

Registered User.
Local time
Today, 00:18
Joined
Sep 20, 2007
Messages
489
Something like this maybe:IE.Document.all.Item("Submit").Click
And this would "click" the first button on the page (zero-based collection):
IE.Document.getElementsByTagName("button")(0).Click

Cheers,
Hello
I tried both codes and showing an error of Object Variable or with b block variable not set? I am guessing I put it after the END WITH line

Code:
Public Function FUNC_ChangeAddress()


'Input data into Niche
    Dim IE As Object
   
    Set IE = New InternetExplorerMedium
With IE
    .Visible = True
    .navigate "http://cor1/Address.asp?headerid=" & Mid([Forms]![FRM_TBLALL_FullDetails].[Form]![StaffNo], 3, 8)
End With


For Each win In CreateObject("Shell.Application").Windows
    If win.Name Like "*Internet Explorer" Then
         Set IE = win: Exit For
    End If
Next


'Wait for IE to load
With IE
    Do Until .ReadyState = 4
        DoEvents
    Loop


Set oDoc = IE.Document
'New Address
oDoc.getElementsByName("NewAddress").Item(0).Value = [Forms]![FRM_TBLALL_FullDetails].[Form]![NewAddressDetails]

oDoc.getElementsByName("Reason").Item(0).Value = "Change Of Address"

End With
End Function
 

bastanu

AWF VIP
Local time
Yesterday, 16:18
Joined
Apr 13, 2010
Messages
1,402
I don't see where you tried any of them them, should go inside the With statement:

Code:
Public Function FUNC_ChangeAddress()


'Input data into Niche
Dim IE As Object
  
Set IE = New InternetExplorerMedium
With IE
    .Visible = True
    .navigate "http://cor1/Address.asp?headerid=" & Mid([Forms]![FRM_TBLALL_FullDetails].[Form]![StaffNo], 3, 8)
End With


For Each win In CreateObject("Shell.Application").Windows
    If win.Name Like "*Internet Explorer" Then
         Set IE = win: Exit For
    End If
Next


'Wait for IE to load
With IE
    Do Until .ReadyState = 4
        DoEvents
    Loop


    Set oDoc = IE.Document
    'New Address
    oDoc.getElementsByName("NewAddress").Item(0).Value = [Forms]![FRM_TBLALL_FullDetails].[Form]![NewAddressDetails]
    oDoc.getElementsByName("Reason").Item(0).Value = "Change Of Address"
    oDoc.all.Item("Submit").Click
    'oDoc.getElementsByTagName("button")(0).Click or try this line if the one above doesn't work- assumes the Submit button is the first one
End With
End Function

Cheers,
 

Users who are viewing this thread

Top Bottom