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!
 
Basically, this is all you should need to do.

'Dialogbox/Inputbox for user search
Do While UserSearch <> ""
'Your code for steps 1-4...
Session.Activate
'Call Dialogbox/Inputbox again
Loop
 
Currently this is the code I have for opening IE and performing the search.

Declare Sub Wait(objIE As Object)

Sub Main()

Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object, objIE As Object, i as Integer

<Attachmate Commands...>

Set objIE = CreateObject("InternetExplorer.Application")

With objIE

.Visible = True
.Navigate "internal website address"

End With

Call Wait(objIE)

objIE.Document.All("txtcovcode").Value = covcd
objIE.Document.All("txtgroupnum").Value = grpnum
objIE.Document.All("txtgroupbu").Value = bu

objIE.Document.All("btnsearchnow").Click

Call Wait(objIE)

End Sub

Private Sub Wait(objIE As Object)
While objIE.Busy
DoEvents
Wend

While objIE.Document.ReadyState <> "complete"
DoEvents
Wend

Sess1.Activate

I am getting a CALL syntax error on the Sess1.Activate command.
 
For some reason I was thinking you wanted this looped. But, it looks like you just want to do stuff in Attachmate after the search?

Code:
<Attachmate Commands...>
With objIE
  .Visible = True
  .Navigate "internal website address"         
  Call Wait(objIE)
  .Document.All("txtcovcode").Value = covcd
  .Document.All("txtgroupnum").Value = grpnum
  .Document.All("txtgroupbu").Value = bu
  .Document.All("btnsearchnow").Click
  Call Wait(objIE)
End With

'The following will make the session the active window
Sess.Activate

'Prompting for info
sUserInput = InputBox("Prompting for user input...","Need Input")

If you need something more complicated than an InputBox you can create a dialogbox to obtain the info. There are quite a few threads in this forum covering dialogboxes.
 
Thanks. I am pretty comfortable with dialog boxes and the editor. I know the code I need once I get back into the session, I am just having troubles getting back to the session from IE.

Using your code I get a 'Unknown Function: Wait' error.

Do I not need the following in the code? I used this from one of the other threads.

Declare Sub Wait(objIE As Object)

Private Sub Wait(objIE As Object)
While objIE.Busy
DoEvents
Wend

While objIE.Document.ReadyState <> "complete"
DoEvents
Wend


 
Try the AppActivate function instead of Sess1.Activate. Whatever your session displays in the Title Bar is what you put in quotes. Mine works like this:
Code:
AppActivate "SESSION1 - EXTRA! for NetWare"
 
Yeah, you still need your Sub Wait for IE. What I provided should only replace the following from the Main Sub:
Code:
<Attachmate Commands...>

[red]Set objIE = CreateObject("InternetExplorer.Application")[/red]

With objIE
        
.Visible = True
.Navigate "internal website address"
      
End With
        
Call Wait(objIE)
   
objIE.Document.All("txtcovcode").Value = covcd
objIE.Document.All("txtgroupnum").Value = grpnum
objIE.Document.All("txtgroupbu").Value = bu
        
objIE.Document.All("btnsearchnow").Click
               
Call Wait(objIE)

Oh, and it looks like I missed this line...
Set objIE = CreateObject("InternetExplorer.Application")
So put it back in before the With objIE line.

You can use AppActivate, but Sess.Activate is going to be more accurate.

Applies To Objects
Session

Description
Makes the specified session the active window.

Syntax
object.Activate

Element Application
object The Session object.

AppActivate string-expression

Activates an application window.

Parameter Description
string-expression The name (from the title bar) of the application you want to activate. Both the title bar and string-expression must be spelled identically. However, the comparison is not case sensitive.
 
Thanks Skie. I tried the appactivate but the only concern I have with that is that I need this to work for many people and some people have decided to rename their sessions.

This is what I have now

Declare Sub Wait(objIE As Object)
Sub Main()

<attachmate commands...>

Set objIE = CreateObject("InternetExplorer.Application")

With objIE

.Visible = True
.Navigate "internal site"

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)

Private Sub Wait(objIE As Object)
While objIE.Busy
DoEvents
Wend

While objIE.Document.ReadyState <> "complete"
DoEvents
Wend

End With

Sess.Activate

<remaing attachmate commands...>


I am getting an 'Illegal Statement' on the "Private Sub Wait(objIE As Object)" command.

Thanks to everyone for helping out with this. This board is great and I can usually find the answers on other threads. You all do great work!
 
You need to End Sub for the Sub Main before you have Sub Wait.

Code:
Declare Sub Wait(objIE As Object)
Sub Main()

<attachmate commands...>

Set objIE = CreateObject("InternetExplorer.Application")

With objIE

  .Visible = True
  .Navigate "internal site"
   
  Call Wait(objIE)
  
[green]  .Document.All("txtcovcode").Value = covcod
  .Document.All("txtgroupnum").Value = grpnum
  .Document.All("txtgroupbu").Value = bu
  .Document.All("btnsearchnow").Click[/green]

  Call Wait(objIE)
End With
             
Sess.Activate

<remaing attachmate commands...>
[red]End Sub[/red]

Private Sub Wait(objIE As Object)
While objIE.Busy
  DoEvents
Wend

While objIE.Document.ReadyState <> "complete"
  DoEvents
Wend
[red]End Sub[/red]
 
FINALLY! Thank you so much! I was about ripping my hair out trying to figure this out. I really appreciate your help on this!

This is my first request, is there something I need to do to follow up on this?

Thanks again!
 
Okay, so further question.

I'm assuming it's possible to check and see if a particular window is already open no?

Meaning, if the page is already open I would like it to just activate that page, but if not then I would like it to open one.

Is this possible?
 
Code:
Dim oApp As Object
Dim oWin As Object
Set oApp = CreateObject("Shell.Application")
For Each oWin In oApp.Windows
  If InStr(oWin.Name, "Microsoft Internet Explorer") Then
    sURL = oWin.LocationURL
    On Error Resume Next
    Set oTitle = oWin.Document.GetElementsByTagName("title")
    On Error Goto 0
    If oTitle Is Nothing Then
      MsgBox oWin.Name & Chr(10) & sUrl
    Else
      MsgBox oTitle(0).innerHTML & " - " & oWin.Name & _
        Chr(10) & sURL
    End If
    Set oTitle = Nothing
  End If
Next

If it has a title it's an internet explorer window. If it doesn't, it's an explorer window. If you find the window you want based on URL or name, you just AppActivate it.
 
How do you stay so patient helping those of us who are way out of our league when it comes to this stuff?

So how would this work for IE 7.0 and searching through Tabbed pages...if at all? Let's say I have an IE window open with 4 different tabs...is it possible for it to search through those as well?

Thanks again for not only helping but doing so kindly.
 
Skie said:
You can use AppActivate, but Sess.Activate is going to be more accurate.

I just wish I had known about Sess.Activate a while back. When I tried to view the EXTRA library in the macro editor it would always crash on my old PC. It's (inconveniently) not listed in the help topics. I've hunted around in the object library in VBA but never saw this until now. You learn something new everyday.
 
I haven't done much with IE7.0. I did a quick search on how you'd find out what was in each tab, but couldn't find any code for it. I don't know if it's a simple as something like:

For i = 1 to oWin.Documents.Count
Set oTab = oWin.Documents(i)
Next

You might want to try posting in an IE forum or either vbscript or javascript forums.
 
Okay, I'm having trouble understanding what information needs plugged in where...or what exactly the code is doing/looking for etc...

The window I am looking for is an IE window that will always have the same Title on the display bar but will not always have the same address. So I would only want to search for the page display Title. If the page is open then I want to activate it, if it is not then I would like to open a page to it.

So let's say that the display title for my page is "Display Title".

Where does that info go in the code?

What does the Chr(10) & sURL command refer to?

What does this command mean, 'MsgBox oTitle(0).innerHTML & " - " & oWin.Name & _'?

Where do I put the AppActivate command?

Sorry, I am used to working within Attachmate and this is the first I've moved to other applications. Any more help is greatly appreciated.


 
Replace this:
MsgBox oTitle.innerHTML & " - " & oWin.Name & Chr(10) & sURL
With this:
If oTitle(0).innerHTML = sTitle Then
oWin.Focus
End If

You can use the oWin.Focus (it may need to be oWin.Document.Focus), since it'll be more reliable than AppActivate.
 
I'm getting a ton of errors trying to use this.

Set oApp = CreateObject("Shell.Application")

For Each oWin In oApp.Windows

If InStr(oWin.Name, "Microsoft Internet Explorer") Then
sURL = oWin.LocationURL
On Error Resume Next
Set oTitle = oWin.Document.GetElementsByTagName("OBS - Online Benefits Search")
On Error Goto 0

If oTitle Is Nothing Then
MsgBox oWin.Name & Chr(10) & sUrl

Else

If oTitle(0).innerHTML = sTitle Then
oWin.Focus
End If

End If

Else
Set oTitle = Nothing

End If

Next


The first error is on the 'For Each' command, I am getting 'FOR syntax error'.

Then I am getting 'Unknown array or function: oTitle' on the If oTitle(0) line.

Then there are several 'FOR and NEXT statements must be in same block'.
 
Sorry, I forgot EB doesn't have For Each
Code:
Dim oApp As Object
Dim oWin As Object
Dim oTitle As Object
Dim iApp As Integer
Dim sURL As String

Set oApp = CreateObject("Shell.Application")
For iApp = 1 To oApp.Windows.Count
 Set oWin = oApp.Windows(iApp)
 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
     oWin.Focus
   End If
  End If
 End If
Next
 
Awesome, thanks! It compiles successfully but when I run it I am getting an 'object error, Line Number: 86'. Line 86 is...

Set oWin = oApp.Windows(iApp)

Here is what I have...

Set oApp = CreateObject("Shell.Application")

For iApp = 1 To oApp.Windows.Count

Set oWin = oApp.Windows(iApp) ***This is line 86

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

oWin.Focus

End If

End If

End If

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top