Excel and WRQ Reflections

Weifeng

New Member
Joined
Oct 5, 2003
Messages
20
:banghead:
Well, I've searched this board and others. I've even called our IT help desk (joke). So, I'm turning to the board for this one.

I'm trying to copy from an Excel cell into an active Reflections field, then copy the results into Excel.I've referenced the Reflections and Excel objects in the VBA editor.


I can launch Excel from Reflections and vice-versa (that's in the help files).

What I can't figure out is how to control the newly activated program once its up.
 
It's been awhile since I've been in front of a machine with Reflection. So this is from memory. Firstly, please post what code you have. Most of the programming I did with Reflection was based upon the retrieval of data and not much of any input. However, I did use automated input for navigation, logging on, ect... There is at least one method similiar to sendkeys. Here is a link to a thread I posted to in the past. You are only the second person that has requested info using this software.

http://www.mrexcel.com/board2/viewtopic.php?t=25640

You will see that I used the "Transmit" method to send variable length strings. There are also key constants and I believe the method used is called "TransmitTerminalKey". One of the methods I used the most was the "GetText" method. There are a handful of others as well. You supply four coordinates. ColumnStart,RowStart,ColumnEnd,RowEnd such as
GetText(0,1,0,30) to get the first 30 characters from line one or your terminal screen. Here is an ad-hoc code example with brief explanations.

Running from Reflection Session:

Code:
Sub HiddenSession_WORKSCHED()

Dim str_Get_String_From_Excel As String
Dim str_Get_String_From_Reflection As String
Dim obj_Excel_WorkBook As Excel.Workbook
Dim str_My_WorkBook_Path As String

str_My_WorkBook_Path = "C:\Documents and Settings\" & _
    "Administrator.THOMAS-7610E5CC\Desktop\Book1.xls"
    
'you will need to set a reference to the proper Excel library
Set obj_Excel_WorkBook = GetObject(str_My_WorkBook_Path)

'read the contents of Sheet1 cell a1 into a variable
str_Get_String_From_Excel = _
    obj_Excel_WorkBook.Sheets("Sheet1").Cells(1, 1).Value

'you will need some investigation into Reflections methods to
'figure out cursor placement if necc.  After positioning
'the cursor, use the Transmit method to place the contents of
'the variable above
Session.Transmit str_Get_String_From_Excel

'you may need to append a return character on the end such as...
Session.Transmit str_Get_String_From_Excel & Chr(13)
    

'you will now need to use one of several methods available to read
'from the terminal screen into a variable.  For the sake of this
'example, we'll use the GetText method.  This assumes that we are looking
'for a string called "MyString" with these coordinates.

'BeginningRow = 3
'EndingRow = 3
'BeginningColumn = 1
'EndingColumn = 8

str_Get_String_From_Reflection = Session.GetText(3, 1, 3, 8)

'place the string in Sheet1 cell b1
obj_Excel_WorkBook.Sheets("Sheet1").Cells(2, 1).Value = _
    str_Get_String_From_Reflection
    

'close and save the workbook
obj_Excel_WorkBook.Close True

'other code and cleanup code...

End Sub


WRQ's website has manuals which are free to download covering the object model and some of the constants. You may or may not have VBA help installed on yours???

I hope this helps. If you run into any problems, just post away and maybe we can figure it out. As for myself, I never was able to locate any information on the web to help me along with WRQ's products. Their object model is excellent as far as I'm concerned and fairly easy to work with. Good Luck!

Tom
 
Upvote 0
Tom,

Thanks for the help. This is the code I've come up with based on your example:


Sub HiddenSession_WORKSCHED()

Dim str_Get_String_From_Excel As String
Dim str_Get_String_From_Reflection As String
Dim obj_Excel_WorkBook As Excel.Workbook
Dim str_My_WorkBook_Path As String

str_My_WorkBook_Path = "C:\Documents and Settings\blah\blahblah\book2.xls"

Set obj_Excel_WorkBook = GetObject(str_My_WorkBook_Path)


str_Get_String_From_Excel = _
obj_Excel_WorkBook.Sheets("Sheet1").Cells(2, 1).Copy


Session.WaitForEvent rcEnterPos, "30", "0", 21, 13
Session.WaitForDisplayString "ITEMNO=>", "30", 21, 2
Session.Paste
Session.TransmitTerminalKey rcIBMEnterKey


At this point, the cell data is entered and transmitted resulting in a screen full of info. I can figure out the column coordinates.

I'm getting an object error at:

obj_Excel_WorkBook.Sheets("Sheet1").Cells(2, 2).Value = _
str_Get_String_From_Reflection

...the mainframe is down for the evening, so I'll have to wait til tomorrow to tweak the code.

Once I get this finished, is there a way to make this macro run for each item in column A?


Thank you again :bow:
 
Upvote 0
Weifeng

I did not get an error but am having other problems with this code. I don't know why? I'm going to post my problem and see if anybody can help.

Tom
 
Upvote 0
If you have formulas in Column A which are being used then change to:

Code:
 For Each rng_Range_Constants_Col_A In _
        obj_Excel_WorkBook.Sheets("Sheet1"). _
        Columns(1).SpecialCells(xlCellTypeConstants + xlCellTypeFormulas)

Try:

Code:
Sub HiddenSession_WORKSCHED()

    Dim str_Get_String_From_Excel As String
    Dim str_Get_String_From_Reflection As String
    Dim obj_Excel_WorkBook As Excel.Workbook
    Dim str_My_WorkBook_Path As String
    Dim rng_Range_Constants_Col_A As Excel.Range
    
    str_My_WorkBook_Path = "C:\Documents and Settings\blah\blahblah\book2.xls"
    
    Set obj_Excel_WorkBook = GetObject(str_My_WorkBook_Path)
    
    'thanks Ivan
    Windows(obj_Excel_WorkBook.Name).Visible = True
    
    'loop here
    For Each rng_Range_Constants_Col_A In _
        obj_Excel_WorkBook.Sheets("Sheet1"). _
        Columns(1).SpecialCells(xlCellTypeConstants)
    
        str_Get_String_From_Excel = rng_Range_Constants_Col_A.Value
        
        Session.WaitForEvent rcEnterPos, "30", "0", 21, 13
        Session.WaitForDisplayString "ITEMNO=>", "30", 21, 2
        Session.Paste
        Session.TransmitTerminalKey rcIBMEnterKey
        'Session.WaitForSilence ?
        
        'At this point, the cell data is entered and transmitted resulting
        'in a screen full of info. I can figure out the column coordinates.
        
        'I'm getting an object error at:
        
        'place the results in column B
        rng_Range_Constants_Col_A.Offset(0, 1).Value = _
            str_Get_String_From_Reflection
    Next

    'stuff here
End Sub
 
Upvote 0
Tom,

This code works when running Reflections(already active) from Excel:

Sub copytoreflections()

Dim Session As Object
Set Session = GetObject(, "ReflectionIBM.Session")
Selection.Copy
Range("a3").Select

Session.Connect
With Session
.WaitForEvent rcEnterPos, "30", "0", 21, 13
.WaitForDisplayString "ITEMNO=>", "30", 21, 2
.Paste
.TransmitTerminalKey rcIBMEnterKey
.SetSelectionStartPos 3, 15
.WaitForEvent rcEnterPos, "30", "0", 21, 13
.WaitForDisplayString "ITEMNO=>", "30", 21, 2
.ExtendSelectionRect 3, 26
.CopySelection
End With

What I can't seem to figure out is how to paste the Reflections data back to excel.
 
Upvote 0
Or

ActiveSheet.Paste

?

But I use GetText all the time, instead of using Select/Copy in Reflections... just curious, but, wouldn't it be faster/better to transfer it directly ?
 
Upvote 0
Using this that you have already pointed out ?

str_Get_String_From_Reflection = Session.GetText(3, 1, 3, 8)

or like this ?

obj_Excel_WorkBook.Sheets("Sheet1").Cells(2, 1).Value = Session.GetText(3, 1, 3, 8)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top