'==============================================================================
'
' MACRO NAME: excel.ebm
' DATE WRITTEN: 11/21/97, Attachmate Automation Support (ng)
' DESCRIPTION: For use with EXTRA! Personal Client 6.x (and derivatives).
' Also requires 32-bit Microsoft Excel to be installed.
'
' NOTES: This macro illustrates how an Excel spreadsheet can be accessed
' and manipulated from within an EXTRA! Basic macro. The macro does
' the following steps:
' 1. Connect to the currently active EXTRA! session.
' 2. Start Excel.
' 3. Create an new .xls file (workbook) and save it.
' 4. Copy the current screen in EXTRA! to the Excel worksheet.
' 5. Save the worksheet.
'
' EXTRA! Basic and Excel VBA are extremely similar. Note that this
' macro will run perfectly if the body of it is copied to a Sub in
' an Excel module.
'
' © Copyright 1989-1997, Attachmate Corporation. All Rights Reserved.
'
' This macro is provided as an example only. It is provided as-is,
' without warranty or support from Attachmate Corporation.
'
'==============================================================================
Sub Main
dim sys as Object, sess as Object, xl as Object, wb as Object
dim iCount as Integer, iRows as long, iCols as long
dim sFile as String, aline as string
sFile = "C:\Documents and Settings\WinblowME\Desktop\Excel.xls"
'####################################################################################################
'##### GET ACCESS TO THE TOP LEVEL E!PC OBJECT...
'####################################################################################################
set sys = CreateObject("Extra.System")
if sys is nothing then
msgbox("Could not create Extra.System...is E!PC installed on this machine?")
exit sub
end if
'####################################################################################################
'##### GET ACCESS TO THE CURRENTLY ACTIVE SESSION...
'####################################################################################################
set sess = sys.ActiveSession
if sess is nothing then
msgbox("No session available...stopping macro playback.")
exit sub
end if
'####################################################################################################
'##### START EXCEL...IT WILL NOT BE VISIBLE YET, BUT WILL STILL BE IN MEMORY....
'##### THIS IS THE SAME AS STARTING EXCEL WITH NO CURRENT WORKBOOK
'####################################################################################################
set xl = CreateObject("Excel.Application")
if xl is nothing then
msgbox("Could not create Excel.Application...is Excel installed on this machine?")
exit sub
end if
'####################################################################################################
'##### CREATE A NEW WORKBOOK...THIS IS JUST LIKE CHOOSING 'FILE-NEW...'
'####################################################################################################
set wb = xl.Workbooks.Add
if wb is nothing then
msgbox("Add method of Excel Workbooks object failed.")
xl.Quit
exit sub
end if
'####################################################################################################
'##### SAVE THE NEW WORKBOOK JUST CREATED...
'##### AN ERROR WILL OCCUR IF THIS FILE CURRENTLY EXISTS AND THE USER CHOOSES
'##### NOT TO REPLACE THE EXISTING OR CHOOSES CANCEL...
'##### AN ERROR WILL ALSO OCCUR IF THE SPECIFIED .XLS IS CURRENTLY OPEN,
'##### SO CLOSE IT BEFORE RUNNING THIS MACRO....
'####################################################################################################
On Error GoTo error_exit
wb.SaveAs(sFile)
iRows = sess.Screen.Rows
iCols = sess.Screen.Cols
'####################################################################################################
'##### COPY THE CURRENT SCREEN TO THE WORKSHEET...
'##### IT'S LIKELY TO LOOK BEST IF A NON-PORPORTIONAL FONT IS USED.
'####################################################################################################
for iCount = 1 to iRows
aline = sess.Screen.GetString(iCount, 1, iCols)
wb.WorkSheets("sheet1").Cells(iCount, 1).Value = aline
wb.WorkSheets("sheet1").Cells(iCount, 1).Font.Name = "Courier New"
next iCount
'SAVE THE CHANGES TO THE WORKBOOK THEN QUIT EXCEL...
wb.Save
error_exit:
xl.Quit
if err then
msgbox sFile + " was not replaced."
else
msgbox "Created " + sFile
end if
exit sub
End Sub