PDA

View Full Version : Copying text from SmarTerm into Excel with VBA



ashburton88
09-05-2016, 08:10 AM
Hi,

I'm working on a macro to replace something we have been using for many years running in WRQ Reflection, but now have to run through SmarTerm instead.

I've got the majority of the code worked out, and I'm able to copy using VBA into the relevant excel cells, however I'm currently using exact column/row references to select the data which isn't going to work for all of the needs of the report, as the position of the data in SmarTerm can change based on the results of the query.

I'm using Session.StringWait.MatchString to find specific text to allow input, but for some reason I can't get this to work to then copy the entire row on which the found text is on, is this something that's possible with VBA & SmarTerm? I can't locate this as an option in the help manual they provide.

Here's the code I've got currently for the search and select, currently the macro just hangs as it seems it can't find the specified text

Session.StringWait.MatchString "SEARCH TEXT"
Session.StringWait.Start
If Session.StringWait.Status = 1 Then
SearchText = Session.SelectScreenAtCoords(Session.FoundTextRow, 20, Session.FoundTextRow, 45)
If SearchText Then
SearchText$ = Session.ScreenText(Session.FoundTextRow, 20, 1, 25)
rng_Range_Constants_Col_A.Offset(0, 4).Value = "SEARCH TEXT: " & SearchText$
Else
rng_Range_Constants_Col_A.Offset(0, 4).Value = "NOTHING FOUND"
End If
End If

FoundTextRow was something we used in the old Macro, I don't know if this will continue to work with SmarTerm or not, so if not if there's an alternative I need to use I'd welcome support/suggestions on this.

SamT
09-05-2016, 10:04 AM
I have no clue what the code isd oing, but this may help :dunno:


Session.StringWait.MatchString "SEARCH TEXT"
Session.StringWait.Start

Const Secs As Double = 0.000011574 'Seconds = 1 / 24 * 60 * 60
Do while Session.StringWait.Status = [Not ready for Primetime] '???
Application.Wait (Now + 2 * Secs)
DoEvents
Loop

If Session.StringWait.Status = 1 Then
SearchText = Session.SelectScreenAtCoords(Session.FoundTextRow, 20, Session.FoundTextRow, 45)
If SearchText Then
SearchText$ = Session.ScreenText(Session.FoundTextRow, 20, 1, 25)
rng_Range_Constants_Col_A.Offset(0, 4).Value = "SEARCH TEXT: " & SearchText$
Else
rng_Range_Constants_Col_A.Offset(0, 4).Value = "NOTHING FOUND"
End If
End If