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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not able to run Extra macro from VBA editor(Excel)

Status
Not open for further replies.

deterdangler

Programmer
Jan 7, 2012
6
0
0
US
Hi Everyone,

I am facing problem in not being able to run Extra macro from vba editor(excel).


Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions

MsgBox Sessions.Count

If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If

g_HostSettleTime = 10000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If


I am always getting the error : "Could not create the Session object. Stopping macro playback."

Any clues?
 


hi,

Do you have a Session opened already in Attachmate, when you run this macro?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi SkipVought,

Yes session is open but i am getting the error: Could not create the Session object. Stopping macro playback.

When i run the same script from Attachmate Macro editor it is running fine.
 



Do you really need the Sessions object, as you are later setting the Sess0 to the active session?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks SkipVought for the reply..

Msgbox System.Sessions.count prints the value as "0" while there are two active sessions open.

I need to send some data to any open active session.

I dont need Sessions object if activesession is returned from System object.
 


I just ran your code as posted from Excel 2007 VB Editor. I did NOT run the code in Extra Basic; rather in Excel VBA. The only changes I had to make were to 1) change Global to Public for your two global variables and 2) declare the OldSystemTimeout& variable, since I have Option Explicit set in the VB Editor in Excel.

I make EXCLUSIVE use of Excel VBA rather than Extra VB, because I prefer to drive a Lamborghini than a Yugo. The analogy is palpable.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


BTW, I can duplicate your symptoms EXACTLY, by NOT opening an Extra!Attachmate session, and then running your code.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
SkipVought,

When i run the same code in Excel 2003 VBA Editor, it is working perfectly..

I don't know what is wrong with the Excel 2007.

Your analogy is real regarding Extra macro vs VB Macro :)
 
Hi Deter

I'm not very experianced with macro's between excell an
and attachmate however here is some code which I sharing data between attachmate screens and excell and works fine

Sub Macro Name()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 0 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Objects
Dim Sess0 As Object
SessName0$ = "C:\Program Files\Attachmate\EXTRA!\Sessions\Attachmate session name.EDP"

Set Sess0 = Sessions.Item(SessName0$)
If Sess0 Is Nothing Then
Err = MsgBox(SessName0 + " is not currently open. Open it?", 1)
If 1 = Err Then
Err = 0
Set Sess0 = Sessions.Open(SessName0)
If Err Then
MsgBox ("Failed to open " + SessName0 + ". Stopping playback")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Failed to open " + SessName0 + ". Stopping playback")
Stop
End If
End If
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

Dim Sess1 As Object
SessName1$ = "\\NA-11\burrowr6\My Documents\Programs\Billing\2nd Attachmate session name name.EDP"

Set Sess1 = Sessions.Item(SessName1$)
If Sess1 Is Nothing Then
Err = MsgBox(SessName1 + " is not currently open. Open it?", 1)
If 1 = Err Then
Err = 0
Set Sess1 = Sessions.Open(SessName1)
If Err Then
MsgBox ("Failed to open " + SessName1 + ". Stopping playback")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Failed to open " + SessName1 + ". Stopping playback")
Stop
End If
End If
If Not Sess1.Visible Then Sess1.Visible = True

Dim Excel As Object
Dim Session As Object
Dim MyScreen As Object
 
Thanks guys,

Sorry for late reply..I found out the problem.

I was running the above pasted code in Excel 2007 but when i run the same code in excel 2003 it was working fine.

Thanks
Deter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top