Auto Click Internet Explorer button in VBA

stu_c

Registered User.
Local time
Today, 16:10
Joined
Sep 20, 2007
Messages
492
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
 
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,
 
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
 
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

Back
Top Bottom