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!

Macro to toggle from Extra to Excel and back. 1

Status
Not open for further replies.

TA7EDDY

Technical User
Feb 6, 2007
2
US
I need help writing a macro that can toogle between Extra and Excel. I have macros in Extra that copies data and then I have a macro attached to a button that paste the data and formats it in a spreadsheet. I want the macro to actually copy the data, activate Excel spreadsheet, run excel macro and then return to Extra and pull next range of data. I know it is possible but cannot figure it out. This is what I have in Extra.


' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' 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 = 3000 ' milliseconds

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

' Get the necessary Session Object
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
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events

Dim Tran As Object
Dim MyScreen As Object
Set MyScreen = Sess0.Screen

Set Tran = MyScreen.Area(13,16,21,20,,3)
Tran.Select
Tran.Copy




'Sess0.Screen.WaitHostQuiet(100)

'Sess0.Screen.Select(13,20,20,40)
'Sess0.Screen.Copy

System.TimeoutValue = OldSystemTimeout
End Sub
 
TA7EDDY..
Here is one I got from the forum, I've played with it and it seems to work like a dream......




Sub ScreenCapture()

'--------------------------------------------------------------------------------
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 = 10 ' milliseconds
OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
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
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)


' This section of code contains the recorded events

System.TimeoutValue = OldSystemTimeout

'Extra Object
Dim Sys_Obj As Object, Sess_Obj As Object, SPOKScreen_Obj As Object
Set SPOKScreen_Obj = Sess0.Screen

'Excel Object
Dim Excel_Obj As Object, Excel_Sheet As Object
Set Excel_Obj = GetObject(, "excel.application")
Set Excel_Sheet = Excel_Obj.Workbooks("ScreenCapture1.xls").Worksheets(2) 'Change this part according to which ever worksheet your working from

Dim Extra_Col As Integer
Dim Extra_Row As Integer
Dim Extra_Page As Integer
Dim Excel_Row As Integer
Dim Excel_Col As Integer
Dim result As String

LastExcelRow = Excel_Sheet.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1).Row
For Excel_Row = InputBox("Input Starting Row") To LastExcelRow
SPOKScreen_Obj.SendKeys ("<Home><EraseEOF>")
SPOKScreen_Obj.SendKeys ("dcs")
SPOKScreen_Obj.MoveTo 1, 9
SPOKScreen_Obj.PutString Excel_Sheet.Cells(Excel_Row, 1).Value
SPOKScreen_Obj.SendKeys ("<enter>")
result = SPOKScreen_Obj.GetString(24, 2, 6)
'You should be on Extra Screen for column one of start row of Excel, now I'll write something to Excel column 3 on the same row.
Excel_Sheet.Cells(Excel_Row, 2).Value = result
SPOKScreen_Obj.WaitHostQuiet (g_HostSettleTime)

result = SPOKScreen_Obj.GetString(7, 46, 22)
'You should be on Extra Screen for column one of start row of Excel, now I'll write something to Excel column 3 on the same row.
Excel_Sheet.Cells(Excel_Row, 3).Value = result

System.TimeoutValue = OldSystemTimeout

Next Excel_Row

End Sub


 
Use the information for declaring your Extra objects in VBA provided in Calc's faq99-4069.

Then move your extra macro over to VBA and run everything from there. If you've tried this and still have problems or questions post back.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top