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

Can't get EBM macro to work from Extra sessions to Word 2007 Doc

Status
Not open for further replies.

jaynlola

Technical User
Aug 2, 2013
4
US
I'm trying to automate redundant letters in Word 2007. I made a macro to do just that, but my currents skills cannot find where my error is. Can someone please inform me of my mistake(s)? Basically, I want to copy from various screens of 'Extra' to the same document for each customer; while also having the Word doc stay Active (not closing and reopening each time). I've put 'labels' in the Word doc and have referenced them correctly. Extra, however, doesn't like my macro.

Thank you.

Declare Function MyFunction()

Sub Main

call MyFunction()

Function MyFunction()
Dim wrd As Object
Dim Session As Object
Dim System As Object
Dim MyScreen as Object

Dim CustomerName as String
Dim CustomerAddress as String
Dim CustomerAddress2 as String
Dim LienHolderName as String
Dim LienHolderAddress as String
Dim LienHolderAddress2 as String
Dim AccountNumber as String
Dim PayoffAmount as String
Dim VinNumber as String
Dim LoanNumber as String


Set System = CreateObject("EXTRA.System")
Set Session = System.ActiveSession
Sess0.Screen.Sendkeys("va")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime
Set MyScreen = Session.Screen
Set the default wait timeout value
g_HostSettleTime = 1000 ' milliseconds

CustomerName =MyScreen.GetString(1,40,30)
StreetAddress =MyScreen.GetString(13,16,20)
StreetAddress2 =MyScreen.GetString(13,37,25)

Sess0.Screen.Sendkeys("<Esc>[d~<Esc>[d~ud<Ctrl+V>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

LienHolderName =MyScreen.GetString(6,53,40)
LienHolderAddress =MyScreen.GetString(8,57,40)
LienHolderAddress2 =MyScreen.GetString(9,53,20)
AccountNumber =MyScreen.GetString(6,9,23)
PayoffAmount =MyScreen.GetString(6,34,8)
VinNumber =MyScreen.GetString(13,15,18)

Sess0.Screen.Sendkeys("<Esc>[V~<Esc>[V~<Esc>[V~<Esc>[V~")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

LoanNumber =MyScreen.GetString


Set wrd = CreateObject("Word.application")
wrd.Documents.Open "C:\Documents and Settings\e576009\Desktop\Refi_macro_letter.docm"
wrd.Visible = True

wrd.ActiveDocument.CustomerName.Caption= (CustomerName)
wrd.ActiveDocument.CustomerAddress.Caption= (CustomerAddress)
wrd.ActiveDocument.CustomerAddress2.Caption= (CustomerAddress2)
wrd.ActiveDocument.LienHolderName.Caption= (LienHolderName)
wrd.ActiveDocument.LienHolderAddress.Caption= (LienHolderAddress)
wrd.ActiveDocument.LienHolderAddress2.Caption= (LienHolderAddress2)
wrd.ActiveDocument.AccountNumber.Caption= (AccountNumber)
wrd.ActiveDocument.PayoffAmount.Caption= (PayoffAmount)
wrd.ActiveDocument.VinNumber.Caption= (VinNumber)
wrd.ActiveDocument.LoanNumber.Caption= (LoanNumber)


Set wrd = Nothing

End Function

Sub End
 
Hi,
Code:
LoanNumber =MyScreen.GetString

What string row, column, length???

THAT could be one reason.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks!

I fixed that portion, but it seems to not initiate from the start. Is my organization incorrect?
 
the Extra VB Editor is .... well it's poor!

I almost NEVER code in Extra! I do nearly all my coding in Excel VBA, as I'd much rather drive a cadillac than a yugo.

Pasting your code into a decent editor, IMMEDIATELY highlighted these two issues.

Anyhow...
Code:
    Sess0.Screen.WaitHostQuiet(g_HostSettleTime[highlight][b])[/b][/highlight]
    Set MyScreen = Session.Screen
[highlight][b]'[/b][/highlight]   Set the default wait timeout value

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Could someone please tell me why my macro fails to execute?
 
jaynlola,

i'm not able to compile your code. it highlights errors immediately. One error that catches my eye is on your last line,
"sub end". you have your function nested within your main code. check out the Help files for an example.

did you try recording a macro first, so that you get the body of macro correct?

 
Here's the code if I was to 'record' it live; although I need it to copy certain coordinates and paste into the Word doc (as posted above):


Code is as follows -
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "C:\Program Files\Extra Sessions\RCO\Retail-Direct.edp"
' Date: Wednesday, August 07, 2013 12:02:45
' User: e576009
'--------------------------------------------------------------------------------

' 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 = 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)

' This section of code contains the recorded events
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Copy
Sess0.Screen.Sendkeys("va<Esc>[d~<Esc>[d~ud<Ctrl+V><Esc>[V~<Esc>[V~<Esc>[V~<Esc>[V~")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

System.TimeoutValue = OldSystemTimeout
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top