Two common tasks seem to be integrating RE with an Excel file. This can mean two things. Either from a plugin or some RE:VBA code opening a Excel file and extracting the data or it can mean that from within Excel VBA access the RE objects to retrieve some data. The way you handle the two scenarios is quite different.
If you are trying to connect to Raiser’s Edge from Excel you will need the API module. You connect to RE using the REAPI object and initialize it with a serial number and optionally user name and password. You then use the API in exactly the same way as you would from within RE, i.e. via VBA or any other API application.
If you want to open up Excel from RE then you will need to create the application objects. This is shown in the example below:
Dim objExcel As Excel.Application ' Excel application Dim objBook As Excel.Workbook ' Excel workbook Dim objSheet As Excel.Worksheet ' Excel Worksheet Dim oConstit As New CRecord oConstit.Init REApplication.SessionContext Set objExcel = CreateObject("excel.application") 'Starts the Excel Session Set objBook = objExcel.Workbooks.Open("C:test.xls") For Each objSheet In objBook.Sheets If UCase(objSheet.Name) = "Sheet1" Then oConstit.Load CLng(objSheet.Range("A2").Text) objSheet.Range("A3").Text = oConstit.Fields(RECORDS_fld_FULL_NAME) Exit For End If Next objSheet objBook.Save If Not objBook Is Nothing Then objBook.Close Set objBook = Nothing End If If Not objExcel Is Nothing Then objExcel.Quit Set objExcel = Nothing End If
This is quite self-explanatory code, although Excel has an object model just as RE does which is very large and takes a while to get to understand. There is plenty of Excel API information on MSDN.
One thought on “Integrating with Excel”
Comments are closed.