VBA code stops midway after Interacting with Internet Explorer

Ombir

Active Member
Joined
Oct 1, 2015
Messages
433
I was trying to help someone with automation of file upload via Internet explorer. I've compiled an Autoit script to upload the file.

The problem is that code stops at
Code:
 media.click
and ask for user interaction to select the file from Select file dialogue window.

I want to execute Upload.exe through Shell command which automate the user interaction process. However code pause before this line.

Is there any way to Set this Select file dialogue window to the background and resume the execution of Vba code to Shell command?

Code:
Dim ie          As InternetExplorer
Sub Ombir_08Jan2017()
Dim doc         As HTMLDocument
Dim msg         As String
Dim Statusbox   As Object

Set ie = New InternetExplorer
msg = "Image Testing"

With ie
    .Visible = True
    .Navigate "www.facebook.com/"
    Call IEReady
End With

Set doc = ie.document

doc.getElementById("email").Value = "jaryszek@o2.pl"
doc.getElementById("pass").Value = "Testtest1234"
doc.getElementById("loginbutton").Click
   Call IEReady
Do While Statusbox Is Nothing
    On Error Resume Next
    Set Statusbox = doc.getElementsByName("xhpc_message")(0)
Loop

Statusbox.Value = msg

Do While media Is Nothing
    Set media = doc.getElementsByClassName("_n _5f0v")(0)
Loop
On Error GoTo 0
AppActivate Application.Caption
media.Click
Shell ("C:\Test\Upload.exe")
doc.getElementsByClassName("_42ft _4jy0 _ej1 _4jy3 _4jy1 selected _51sy")(0).Click
    Call IEReady
    ie.Quit
End Sub
Sub IEReady()
Do While ie.ReadyState <> 4: DoEvents: Loop
waitfor 1
    Do While ie.Busy
        waitfor 3
    Loop
End Sub
Sub waitfor(ByVal nSec As Long)
nSec = nSec + Timer
    Do While Timer < nSec
       DoEvents
    Loop
End Sub

You can use the Login details in the code. Its a dummy account for testing.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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