View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Copy/Paste problem from another app to Excel

Dan Tabla brought next idea :
I have an application that supports VBA and I'm trying to copy some values
from its
screen into Excel using VBA. If I do it manualy, wont be a problem. Cliping
the text manualy from "Session"
and pasting in Excel gives me the wanted result.(text in Excel will be
pasted in different lines like
the in the original in "Session")

Session Excel

9889790 9889790
9889791 9889791
9889792 9889792

But, when I use the VBA code bellow, the text in Excel wont be in 3
different lines,cells like when I do it manually.
The whole string value will be assigned to same cell and I want to be like
the original cliptext from Session.

Session Excel

9889790 9889790 9889791 9889792
9889791
9889792



Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Dim Sess0 As Object
Set Sess0 = System.ActiveSession


Set MyScreen = Sess0.Screen
Set myarea = MyScreen.Area(StartRow, StartCol, EndRow, EndCol, , 3)
myarea.Select
myarea.Copy
ActiveSheet.Cells(Row, Col).Value = myarea.Value



THANKS EVERYONE FOR ANY SUGGESTION AND COMPILE SUCCESFULLY!


Is this Excel VBA? If so, I don't see where you define the variables
you're using in the Cells property. (Row, Col) Nor do I see where you
define MyScreen and myarea. This suggests you do not have Option
Explicit on the first line in your code module.

Also, once you have a reference to "EXTRA.System" in your System
variable, you can refer to it directly without having to also have a
reference to its Sessions collection (unless you need that for
something later on).

Your code is copying from an area and inserting the contents as the
value of a single cell on the worksheet. Try this:

Set myarea = MyScreen.Area(StartRow, StartCol, EndRow, EndCol, , 3)
myarea.Copy ActiveSheet.Cells(1, 1)

What it does is: it sets the destination parameter for the copy method.
(A1 is the base address to receive 1 col x 3 row paste of data) This
should result in the data being listed in cells A1 to A3, which I
believe is what you want.

Note that I omitted the line where you select the area because it's not
necessary to do that. Once the area is defined, you can take direct
action on it without having to select anything. See below for an
example.

Suggested rewrite:
Sub CopyFromExtra()
Dim System As Object
Set System = CreateObject("EXTRA.System")
If System Is Nothing Then Exit Sub '//in case it failed
System.ActiveSession.Screen.Area(StartRow, StartCol, EndRow, EndCol,
, 3).Copy Destination:=ActiveSheet.Cells(1, 1)
Set System = Nothing
End Sub

Note that the line that acts on the System object is all one line, so
watch the word wrap.

HTH
Garry