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.a ll("CsietI nstance_Ta gNumber"). Value
Cells(i, 2) = externalref
Thanks,
Matt
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.
Application.Wait TimeValue(Now) + TimeValue("00:00:01")
Else
Exit Do
End If
Loop
' Read External Reference
externalref = Connecting_IB.WebBrowser1.
Cells(i, 2) = externalref
Thanks,
Matt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Rob Sampson suggested to you the method CreateObject ("InternetExplorer.Applica tion").
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_DocumentComple te (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("passwo rd").Value = PassWord
pDisp.Document.all("btnSub mit").Clic k
n = n + 1
End If
End If
End If
End Sub
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_DocumentComple
If TypeOf pDisp Is WebBrowser Then
If InStr(pDisp.Document.Title
If n < 4 Then
pDisp.Document.all("userid
pDisp.Document.all("passwo
pDisp.Document.all("btnSub
n = n + 1
End If
End If
End If
End Sub
see this for a better explanation than I can give:
http://msdn2.microsoft.com/en-us/library/39wcs2dh(VS.80).aspx