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

Need Putstring help as paste doesn't work coping activecell.

Status
Not open for further replies.

link99sbc

Technical User
Apr 8, 2009
141
US
' 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 = 300 ' 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 Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object

Set Sys = CreateObject("EXTRA.System")
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen

'Activates the Spreedsheet which is already open
AppActivate "Microsoft Excel - SCOP stats.xls"

'Copies the active cell and moves down to the next cell which makes it the next active cell.
'I do this more than a 1000 times. "Column with over 1000 names"
Sendkeys "%EC{Down}"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Alt tabs back to Extra Session
Sendkeys "%{tab}"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Goes to the home position, tabs to the next variable and
'types Name and goes to the next variable (Field) by default
'since only four characters are required in the first field.
Sess0.Screen.Sendkeys("<Home><Tab>NAME")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Paste the copied cell from Excel in the second variable space or Field if you prefer.
Sendkeys "%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Triggers Extra Session to search a Data Base for the Name that was pasted in the second field.
Sess0.Screen.Sendkeys("<Enter>")

System.TimeoutValue = OldSystemTimeout
End Sub

This works fine in Extra Enterprise but will not paste in Extra Extreme 9.0 SP2
using "%EP" , Sess0.Screen.paste, MyScreen paste, My Area paste. No matter how I write
it, IT WILL NOT PASTE! Any ideas? It will paste using the mouse or keyboard. Putstring might work but I don't know how to get the contents of the active cell and put it at 3,23 in the session. It also needs to clear the entire line first. 3,23 to 3,70 and make the next cell down the next active cell so it will get that cell when I run the macro again. I use appactivate because the excel file is always open.
 


'Activates the Spreedsheet which is already open
AppActivate "Microsoft Excel - SCOP stats.xls"

'Copies the active cell and moves down to the next cell which makes it the next active cell.
'I do this more than a 1000 times. "Column with over 1000 names"
Sendkeys "%EC{Down}"
WHERE are you copying ANYTHING in Excel?????

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Wow, thanks for the fast response.
I use 4 sessions in attachmate. 3 sessions and the excel file are open but minimized in the windows toolbar. When I use the macro with "appactivate" the excel file appears on the screen and copies the active cell then alt-tabs back to the attachmate session and pastes the contents of the active cell at 3,23 in the attachmate session.

When I first open excel file I left click on the cell I want to start on which makes it the active cell. So in the macro %EC{down} copyies the active cell and moves down which makes the next cell active. AtlTab returns to the Session and %EP is supposed to paste (which is the contents of the clipboard). Paste doesn't work in Attachmate Xtreme for some reason. It will paste anything from one session to another with a macro but not from excel to a session unless you use the mouse or keyboard to paste which make the macro useless. It was suggested that I use putstring but I don't know how to write it to capture the contents of the active cell, move down to make the next cell active and put it in the session at 3,23. I hope I'm making this clear. Thanks.
 



Then you have some asynchronous processes occurring. How can you be ABSOLUTELY SURE that the copy occurs BEFORE your PASTE occurs in Extra???

That is no way to code, IMHO.

BTW, I do ALL my Extra coding in Excel VBA. You get much MUCH better control of your process.

Also I never use COPY 'n' PASTE to do this kind of process. I use PutString or the Area function to PLACE the value in the Extra screen at the proper coordinates. I never use the Select method either. Rather reference the cell or screen coordinates explicitly, like..
Code:
for lRow = 2 to Sheet1.UsedRange.Rows.Count
   oScrn.Area(iRow, iCol, iRow, iCol+iLen-1).value = Sheet1.cells(lrow, "A").value
   iCol=iCol +1
next




Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


oops.

I should have incrimeted iRow rather than iCol.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 




that nondiscript statement will not help you get a good response.

Exactly WHAT did you do?

Exactly WHAT happened?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
All I need is a macro in Excel to drop down 1 cell, copy the contents of that cell and put it at row 3 col 23 of my attachmate session without using paste.

Tried using you code but error said I need an Object
 


This is like pulling teeth! Pleeeeease provide CLEAR, CONCISE & COMPLETE information when you ask a question!

but error said I need an Object

error on WHAT statement?

where were you running the code? in Extra or Excel?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sub Putstring()
For lrow = 2 To Sheet1.UsedRange.Rows.Count
oScrn.Area(iRow, iCol, iRow, iCol + iLen - 1).Value = Sheet1.Cells(lrow, "A").Value
iRow = iRow + 1
Next

End Sub

This gets a run-time error 424
Object Required
oScrn.Area(iRow, iCol, iRow, iCol + iLen - 1).Value = Sheet1.Cells(lrow, "A").Value
 
OOH running this from Excel Macro. I would like it to know how to make this work running from attachment macro also.
 



How did you define and set oScrn?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Solved

changed
Sendkeys "%EP"
to
Set MyArea = MyScreen.Area(3,23,3,70)
MyArea.Paste

Seems to be working ok now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top