Link to home
Start Free TrialLog in
Avatar of Aleyna
Aleyna

asked on

Send Key command in VBA

I have a program which automates a webbrowser application within a userform. There were a couple of reasons why this was initialy done like that.

The problem is the program is running the user can not do anything else... For example if you click on something else the macro errors out as it can not function.

My question is: Is there a way to tell Excel to continue sending keys and working with that userform even if the user turns to something else?

Below is part of the code to give you an idea:

' Select the product number
    For j = 1 To 15
        SendKeys "{TAB}", True
    Next j
    SendKeys "{ENTER}", True
    ' wait until browser is free
    Do
        DoEvents
        If Connecting_IB.WebBrowser1.Busy Then 'If Browser is busy waits an extra 1 second
            Application.Wait TimeValue(Now) + TimeValue("00:00:01")
        Else
            Exit Do
        End If
    Loop
    ' Read External Reference
    externalref = Connecting_IB.WebBrowser1.Document.all("CsietInstance_TagNumber").Value
    Cells(i, 2) = externalref
Thanks,



Matt
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it related to how you load the form, either modal or modeless.

see this for a better explanation than I can give:

http://msdn2.microsoft.com/en-us/library/39wcs2dh(VS.80).aspx
Avatar of sp10635
sp10635

Rob Sampson suggested to you the method CreateObject ("InternetExplorer.Application").
You should find a different way to solve your "problem" by the following Code (to be customized to your cases).

With Regards,

E.C.

__________________________

Code.

Option Explicit
Private Const UserName As String = "Some Username"
Private Const PassWord As String = "Some Password"
Private n As Integer

Private Sub CommandButton1_Click()
    WebBrowser1.Navigate ...URL...
End Sub
 
Private Sub WebBrowser1_DocumentComplete (ByVal pDisp As Object, URL As Variant)
    If TypeOf pDisp Is WebBrowser Then
        If InStr(pDisp.Document.Title, ".......") <> 0 Then
            If n < 4 Then
                pDisp.Document.all("userid").Value = UserName
                pDisp.Document.all("password").Value = PassWord
                pDisp.Document.all("btnSubmit").Click
                n = n + 1
            End If
        End If
    End If
End Sub