×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SendKeys from Attachmate to Internet Explorer

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


RE: SendKeys from Attachmate to Internet Explorer

Your use of sendkeys is attempting to edit your macro as it is the active window when you run your script.  Instead of sending "SOME TEXT" to IE your sending it to your macro editor and it assumes your trying to edit the script thats running, hence the error msg.

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

Declare Sub Wait(objIE As Object)

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

Oops, the integer declaration is not needed...

RE: SendKeys from Attachmate to Internet Explorer

(OP)
Thanks for the replies, they are most helpful.

Is objIE.Document.Forms("f").all.item("q").value = "TEST"

Looking for certain things on the webpage.

RE: SendKeys from Attachmate to Internet Explorer

Yes, in Google's HTML source, f is the form name, q is the name of the textbox and btnG is the name of the submit button.

CODE

<form action="/search" name=f>

<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

(OP)
Thankyou, that's been a great help

RE: SendKeys from Attachmate to Internet Explorer

(OP)
WinblowsME - I have tried the code that you posted above, but it returns an error with ref to the following code:
objIE.Document.Forms("f").all.item("q").value = "TEST"

It returns Object value is set to nothing

RE: SendKeys from Attachmate to Internet Explorer

Post your code.

RE: SendKeys from Attachmate to Internet Explorer

Are you using that code for the google page or for the page you're trying to pass information to?

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

Dim oForms, oForm
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

For i = 1 to oForms.Count
  Set oForm = oForms(i)

RE: SendKeys from Attachmate to Internet Explorer

(OP)
I was using the code for Google as a test web site. Just to find the text box and enter some text, if I could get this to work I was going to adapt my code to work with an internal website

RE: SendKeys from Attachmate to Internet Explorer

Then, you'd have to post your code because WinblowsME's code works.

RE: SendKeys from Attachmate to Internet Explorer

(OP)
Thats strange, I have run WinblowsME's code and I get an error saying 'Object set to nothing'

RE: SendKeys from Attachmate to Internet Explorer

Do you get that error on a line?  If you step through the code when do you get the error?

RE: SendKeys from Attachmate to Internet Explorer

(OP)
I get the error on line 19 when I step through the code.



RE: SendKeys from Attachmate to Internet Explorer

Line 19 is blank in the example.  Post the code you're using.

RE: SendKeys from Attachmate to Internet Explorer

(OP)

CODE

1.  Declare Sub Wait(objIE As Object)
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

Don't comment out the Wait procedure because you have to wait until the web page finishes loading before you can access the document objects.

CODE

13.   'Call Wait(objIE)

Typos in red.

CODE

7.  Set objIE = CreateObject("InternetExplorer.Application")

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

(OP)
Finally Cracked it...

I used the following code

CODE

Declare Sub Wait(objIE As Object)

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
I changed the code in green
Thanks for all of your help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close