SendKeys from Attachmate to Internet Explorer
SendKeys from Attachmate to Internet Explorer
(OP)
Hi,
I am trying to write a macro using Attachmate Extra 7.1 to copy from an Extra screen, find the correct opened Internet Explorer window then paste the contents into a blank box on Internet Explorer.
I can get the macro to open a new IE window, navigate to a certaqin website(I used Google) pasted in the correct details and pressed enter.
This was completed using:
Call SendKeys("Some Text")
Call SendKeys("{ENTER}")
This all worked fine.
So then I tried to get the macro to look for the correct open IE window. By looking at the Title of each IE window
The macro finds the correct window but I get an error when I try to use SendKeys..
This is the error message I get:- Cannot edit while macro is running.
Here is my code so far(this code was found on this forum, but used the Document.url
Sub Main
Declare Variables
Dim ie as object
Dim objApp as object
Set object as a Shell type application
Set objApp = CreateObject("Shell.Application")
Create a For loop to search each Application open
for i = 0 to 9
Declare variable strName
strName = ""
On Error Resume Next
strNam equals current open IE window
strName = objApp.Windows(i).Document.title
an if method to confirm correct open IE Window
if InStr(strName,"Google") then
set ie = objApp.Windows(i)
exit for
end If
next
if ie is nothing then
msgbox("IE window not found")
else
end if
Call Sendkeys("SOME TEXT")
End Sub
---------------------------------------------------
Is this an easy fix?
Do I need to create another Sub Method?
Any hlep would be most appreciated
I am trying to write a macro using Attachmate Extra 7.1 to copy from an Extra screen, find the correct opened Internet Explorer window then paste the contents into a blank box on Internet Explorer.
I can get the macro to open a new IE window, navigate to a certaqin website(I used Google) pasted in the correct details and pressed enter.
This was completed using:
Call SendKeys("Some Text")
Call SendKeys("{ENTER}")
This all worked fine.
So then I tried to get the macro to look for the correct open IE window. By looking at the Title of each IE window
The macro finds the correct window but I get an error when I try to use SendKeys..
This is the error message I get:- Cannot edit while macro is running.
Here is my code so far(this code was found on this forum, but used the Document.url
Sub Main
Declare Variables
Dim ie as object
Dim objApp as object
Set object as a Shell type application
Set objApp = CreateObject("Shell.Application")
Create a For loop to search each Application open
for i = 0 to 9
Declare variable strName
strName = ""
On Error Resume Next
strNam equals current open IE window
strName = objApp.Windows(i).Document.title
an if method to confirm correct open IE Window
if InStr(strName,"Google") then
set ie = objApp.Windows(i)
exit for
end If
next
if ie is nothing then
msgbox("IE window not found")
else
end if
Call Sendkeys("SOME TEXT")
End Sub
---------------------------------------------------
Is this an easy fix?
Do I need to create another Sub Method?
Any hlep would be most appreciated
RE: SendKeys from Attachmate to Internet Explorer
You should be sending keys to IE through the object your creating. e.x.
IE.Sendkeys("SOME TEXT")
note: the Call statement is not needed in the example.
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black
RE: SendKeys from Attachmate to Internet Explorer
CODE
Sub Main()
Dim objIE As Object, i As Integer
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True
.Navigate "http://www.google.com"
End With
Call Wait(objIE)
' View the HTML source on Google's page to see the
' f, q and btnG values
objIE.Document.Forms("f").all.item("q").value = "TEST"
'objIE.Document.Forms("f").all.item("btnG").Click
'Call Wait(objIE)
End Sub
Private Sub Wait(objIE As Object)
While objIE.Busy
DoEvents
Wend
While objIE.Document.ReadyState <> "complete"
DoEvents
Wend
End Sub
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
Is objIE.Document.Forms("f").all.item("q").value = "TEST"
Looking for certain things on the webpage.
RE: SendKeys from Attachmate to Internet Explorer
CODE
<input maxlength=2048 name=q size=55 title="Google Search" value="">
<input name=btnG type=submit value="Google Search">
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
objIE.Document.Forms("f").all.item("q").value = "TEST"
It returns Object value is set to nothing
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
If it's the page you're trying to pass information to, then it's very likely the form is not "f" and the item is not "q". The easiest thing to do is simply look at the source to find this information, barring that the following code will get you the names of the forms. Change "form" to "input" for buttons, fields, checkboxes, etc. With "input" type, you might want to msgbox the type as well.
CODE
Set oForms = oIE.Document.GetElementsByTagName("form")
If oForms Is Nothing Then
MsgBox "No forms on this page"
Else
For Each oForm In oForms
On Error Resume Next
MsgBox "Name: " & oForm.Name & vbCrLf & "ID: " & oForm.Id
On Error Goto 0
Next
End If
Also, I don't think EB has a For Each loop, so you may need to change the beginnig of loop to:
CODE
Set oForm = oForms(i)
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
RE: SendKeys from Attachmate to Internet Explorer
CODE
2.
3. Sub Main()
4. Dim objIE As Object
5. dim objApp as object
6.
7. Set objIE = CreateObject"InternetExplorer.Application")
8. With objIE
9. .Visible = True
10. .Navigate "http://www.google.com"
11. End With
12.
13. 'Call Wait(objIE)
14.
15. ' View the HTML source on Google's page to see the
16. ' f, q and btnG values
17.
18. set objApp = objIE.Document.Forms("f").all.item"q").value = "TEST"
19. 'set objApp = objIE.document.forms("q").value = "Test"
20. 'objIE.Document.Forms("f").all.item("btnG").Click
21. 'Call Wait(objIE)
22. End Sub
23.
24. Private Sub Wait(objIE As Object)
25. While objIE.Busy
26. DoEvents
27 Wend
28.
29. While objIE.Document.ReadyState <> "complete"
30. DoEvents
31. Wend
32. End Sub
Line 18 is the problem
RE: SendKeys from Attachmate to Internet Explorer
CODE
Typos in red.
CODE
18. set objApp = objIE.Document.Forms("f").all.item("q").value = "TEST"
Jim, if you use my code and not make a single change, it should run fine.
RE: SendKeys from Attachmate to Internet Explorer
I used the following code
CODE
Sub Main()
Dim objIE As Object, i As Integer
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True
.Navigate "http://www.google.com"
End With
Call Wait(objIE)
' View the HTML source on Google's page to see the
' f, q and btnG values
objIE.Document.All("q").Value = "Test"
objIE.Document.All("btnG").Click
Call Wait(objIE)
End Sub
Private Sub Wait(objIE As Object)
While objIE.Busy
DoEvents
Wend
While objIE.Document.ReadyState <> "complete"
DoEvents
Wend
End Sub
Thanks for all of your help