Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attachmate -> IE -> Attachmate 2

Status
Not open for further replies.

blckngldhwk

Technical User
Feb 14, 2008
46
US
I currently have a macro that runs some commands in a session then opens internet explorer, performs a search from that page, and now i want to get it to go back to the session it was started in and continue to run.

1. Start in Attachmate Session
2. Pull Data

3. Open Internet Explorer to a search page
4. Use data pulled from Attachmate to perform search
(No data pulled from Internet)

6. Return to original Session
7. Prompt a dialog box for user input

I can run steps 1-4 on their own but I need help on the code required to return to the original session. Please assist!
 
try with quotes

Set oWin = oApp.Windows("iApp")

[small]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[/small]
 
Same situation. Compiles but hits an error at that line.
 
Set oWin = oApp.Windows(iApp - 1)

I wasn't sure if it needed the -1 when I originally posted. I tend to use For Each loops with that object and haven't had to deal with it in EB.
 
Fantastic. Okay, it compiles and it runs, now I need to figure out how to arrange the logic.

IF the window is already open, perform

Call Wait(objIE)
objIE.Document.All("txtcovcode").Value = covcod
objIE.Document.All("txtgroupnum").Value = grpnum
objIE.Document.All("txtgroupbu").Value = bu
objIE.Document.All("btnsearchnow").Click
Call Wait(objIE)

If it is not open, perform

Set objIE = CreateObject("InternetExplorer.Application")

With objIE
.Visible = True
.Navigate "
End With

Call Wait(objIE)
objIE.Document.All("txtcovcode").Value = covcod
objIE.Document.All("txtgroupnum").Value = grpnum
objIE.Document.All("txtgroupbu").Value = bu
objIE.Document.All("btnsearchnow").Click
Call Wait(objIE)


I've tried several different variations but am not having any luck.

You've been a great help so far though. Thanks for any additional assistance.
 
Horrible advice sory, I didn't look far enough to see that iApp was an integer and you were looking by index rahter than title.

I really need to avoid hit and runs when I don't have the time to read the whole post.


[small]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[/small]
 
Something like this...
Code:
Dim oIE As Object
Dim oApp As Object
Dim oWin As Object
Dim oTitle As Object
Dim iApp As Integer
Dim sURL As String

Set oIE = Nothing
Set oApp = CreateObject("Shell.Application")
For iApp = 1 To oApp.Windows.Count
 Set oWin = oApp.Windows(iApp - 1)
 If InStr(oWin.Name, "Microsoft Internet Explorer") Then
  sURL = oWin.LocationURL
  Set oTitle = Nothing
  On Error Resume Next
  Set oTitle = oWin.Document.GetElementsByTagName("title">
  On Error Goto 0
  If Not oTitle Is Nothing Then
   If oTitle(0).innerHTML = "OBS - Online Benefits Search" Then
     Set oIE = oWin
   End If
  End If
 End If
Next

If oIE Is Nothing Then
 Set oIE = CreateObject("InternetExplorer.Application")
 With oIE
  .Visible = True
  .Navigate "[URL unfurl="true"]http://wellnetapp.int.wellmark.com/secure/obs/search.asp"[/URL]
  Call Wait(objIE)
 End With
End If

With oIE
 .Document.All("txtcovcode").Value = covcod
 .Document.All("txtgroupnum").Value = grpnum
 .Document.All("txtgroupbu").Value = bu      
 .Document.All("btnsearchnow").Click   
 Call Wait(objIE)
End With

[/code]
 
Compiles successfully, now getting an error while running for the following line...

"Object value is set to Nothing"
If InStr(oWin.Name, "Microsoft Internet Explorer") Then

Code:
Set oIE = Nothing
      
        Set oApp = CreateObject("Shell.Application")
        
        For iApp = 1 To oApp.Windows.Count
        
        Set oWin = oApp.Windows(iApp - 1)
        
        [COLOR=red]If InStr(oWin.Name, "Microsoft Internet Explorer") Then[/color]
        
        sURL = oWin.LocationURL
        
        Set oTitle = Nothing
        
        On Error Resume Next
        
        Set oTitle = oWin.Document.GetElementsByTagName("title")
        
        On Error Goto 0
        
             If Not oTitle Is Nothing Then
        
                  If oTitle(0).innerHTML = "OBS - Benefit Summary Search" Then
        
                  Set oIE = oWin
        
                  End If
             
             End If
             
        End If
        
        Next
        
        If oIE Is Nothing Then
        
        Set oIE = CreateObject("InternetExplorer.Application")
 
        With oIE
        
        .Visible = True
        .Navigate "[URL unfurl="true"]http://wellnetapp.int.wellmark.com/secure/obs/search.asp"[/URL]
           
        Call Wait(objIE)
         
        End With
         
        End If
        With oIE         

        .Document.All("txtcovcode").Value = covcod
        .Document.All("txtgroupnum").Value = grpnum
        .Document.All("txtgroupbu").Value = bu      
        .Document.All("btnsearchnow").Click   
         
        Call Wait(objIE)
         
        End With
 
Okay, I got the macro to compile and to run without error but it is not doing what I had wanted it to do. It is still opening a new window each time, despite there already being a window open... Here is the code that I have...

Code:
        Set oIE = Nothing
      
        Set oApp = CreateObject("Shell.Application")
        
        For iApp = 1 To oApp.Windows.Count
        
        Set oWin = oApp.Windows(iApp - 1)
        
        If InStr(oWin.Name, "Microsoft Internet Explorer") Then
        
        sURL = oWin.LocationURL
        
        Set oTitle = Nothing
        
        On Error Resume Next
        
        Set oTitle = oWin.Document.GetElementsByTagName("title")
        
        On Error Goto 0
        
             If Not oTitle Is Nothing Then
        
                  If oTitle(0).innerHTML = "OBS - Benefit Summary Search" Then
        
                  Set oIE = oWin
        
                  End If
             
             End If
             
        End If
        
        Next
        
        If oIE Is Nothing Then
        
        Set oIE = CreateObject("InternetExplorer.Application")
 
        With oIE
        
        .Visible = True
        .Navigate "**internalsite url**"
           
        Call Wait(oIE)
         
        End With
         
        End If
        With oIE
        
        .Visible = True       

        .Document.All("txtcovcode").Value = covcod
        .Document.All("txtgroupnum").Value = grpnum
        .Document.All("txtgroupbu").Value = bu      
        .Document.All("btnsearchnow").Click   
         
        Call Wait(oIE)
         
        End With
         
End Sub


Private Sub Wait(oIE As Object)

   While oIE.Busy
   
   DoEvents
   
   Wend
   
   While oIE.Document.ReadyState <> "complete"
   
   DoEvents
   
   Wend
   
End Sub

The display title for the window I want to look for is exactly "OBS - Benefit Summary Search - Windows Internet Explorer". I have tried using that and w/o the Windows Internet Explorer portion but it just keeps opening a new window. Any thoughts?
 
Okay, finally figured it out!

The problem was this line

If InStr(oWin.Name, "Microsoft Internet Explorer") Then


The "suffix" for IE is 'Windows Internet Explorer' instead of 'Microsoft Internet Explorer'. I changed that and voila!

Thank you so much again for everything! I am sure I will have some other questions but I'm off for the weekend so take it easy! Enjoy!
 
Modify this section:
Code:
If Not oTitle Is Nothing Then
  If oTitle(0).innerHTML = "OBS - Benefit Summary Search" Then
    Set oIE = oWin
  End If
End If
to:
Code:
If Not oTitle Is Nothing Then
  If InStr(oTitle(0).innerHTML, "OBS - Benefit Summary Search") Then
    Set oIE = oWin
  End If
End If

If that doesn't work, you might want to MsgBox back the oTitle(0).innerHTML to see what it says the title is.
 
Thanks again for everything. The original macro I needed help with has been completed and working great. I have another question regarding another macro. Instead of searching by the Display Name, I would like to now search by the URL of the open internet windows. Is it fairly similar to searching by title? Thanks again for all your help!
 
Yep, just use oWin.LocationURL instead of the oTitle.
 
Code:
If Not oWin.LocationURL Is Nothing Then
       
If oWin.LocationURL(0).innerHTML = "[URL unfurl="true"]http://www.google.com"[/URL] Then
                    
Set oIE = oWin

oWin.Focus
                    
With oIE
        
.Visible = True
.Navigate "[URL unfurl="true"]http://www.tek-tips.com"[/URL]
          
Call Wait(oIE)

End With

This compiles fine but when I run it I get an error that says 'no such property or method' on the line 'If Not oWin.LocationURL is Nothing Then' line. Do you see anything wrong with this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top