Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I tried what you suggested me..Didnt work but thank you so much for your try.
Maybe I m still doing something wrong..Anyway this is the origanl code...Sorry for such a mess.. Global g_HostSettleTime% Global g_szPassword$ Sub RoundToZero2() ' Get the main system object Dim SIR, COMANDA As String Dim StartRow, StartCol, EndRow, EndCol, Row, Col, contoar As Integer Dim Sessions As Object Dim System As Object Set System = CreateObject("EXTRA.System") ' Gets the system object contoar = 0 SIR = "" COMANDA = "" 'On Error GoTo 1 ActiveWorkbook.FollowHyperlink "C:\Program Files\E!PC\Sessions\Session1.EDP", NewWindow:=True 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 = 1000 ' 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) Application.DisplayAlerts = False For Each c In ActiveSheet.Range("A1:D12").Cells c.Select If c.Interior.ColorIndex = 40 Then Exit Sub Else If c.Interior.ColorIndex = 2 Then GoTo 1 If c.Interior.ColorIndex = 3 Then COMANDA = "<ENTER" If c.Interior.ColorIndex = 36 Then COMANDA = "" If c.Interior.ColorIndex = 23 Then COMANDA = "<TAB" If c.Interior.ColorIndex = 3 Or c.Interior.ColorIndex = 23 Or c.Interior.ColorIndex = 36 Then SIR = c.Value & COMANDA Sess0.Screen.SendKeys (SIR) Sess0.Screen.WaitHostQuiet (g_HostSettleTime) GoTo 1 End If If c.Interior.ColorIndex = 39 Then StartRow = c.Value contoar = contoar + 1 GoTo 2 End If If c.Interior.ColorIndex = 54 Then StartCol = c.Value contoar = contoar + 1 GoTo 2 End If If c.Interior.ColorIndex = 47 Then EndRow = c.Value contoar = contoar + 1 GoTo 2 End If If c.Interior.ColorIndex = 35 Then EndCol = c.Value contoar = contoar + 1 GoTo 2 End If If c.Interior.ColorIndex = 37 Then Row = c.Value contoar = contoar + 1 GoTo 2 End If If c.Interior.ColorIndex = 33 Then Col = c.Value contoar = contoar + 1 GoTo 2 End If 'Sess0.Select(StartRow, StartCol, EndRow, EndCol, , 3) Set MyScreen = Sess0.Screen On Error Resume Next 2: If contoar = 6 Then Set myarea = MyScreen.Area(StartRow, StartCol, EndRow, EndCol, , 3) myarea.Select ActiveSheet.Cells(Row, Col).Value = myarea.Value Set System = Nothing End If 1: Next System.TimeoutValue = OldSystemTimeout End Sub "GS" wrote: 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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel copy/paste problem | Excel Discussion (Misc queries) | |||
Copy/Paste problem in Excel 2007 | Excel Programming | |||
problem with excel vba copy/paste. can anyone help? | Excel Programming | |||
Excel Copy/Paste Problem | Excel Discussion (Misc queries) | |||
Excel cut/Paste Problem: Year changes after data is copy and paste | Excel Discussion (Misc queries) |