Do I have to create an equivalent for word, and how would this look (needs
to cope with older version of word), or is there an easier way?
Thanks, Lou
This is what I did for Excel.
' Export whatever records currently displayed to excel. Uses late binding to
allow for different
' versions of office
On Error GoTo ANEError
'define variables
Dim xlApp As Object
Dim xlWorkbook As Object
Dim objRST As Recordset
'Dim strWorkbook As String
Dim strSheetname As String
Dim xlsheet As Object
'create the excel application object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'create a new workbook
'strWorkbook = "NewExport"
Set xlWorkbook = xlApp.Workbooks.Add
'define variables
'create the recordset
Set objRST = Screen.ActiveForm.RecordsetClone
'create a sheet name - must be 30 characters or less
strSheetname = "ANE Business System Export"
'copy data from the recordset to the cells
Set xlsheet = xlWorkbook.Sheets(1)
With xlsheet
.Cells.CopyFromRecordset objRST
.Name = strSheetname
End With
'clean up all variables
Set objRST = Nothing
Set xlsheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
'Fix to ensure the data can be exported more than once without closing
the form and reopening
'setfocus, requery, refresh do not work.
If Screen.ActiveForm.FilterOn = False Then
Screen.ActiveForm.Filter = "True"
Screen.ActiveForm.FilterOn = True
Screen.ActiveForm.FilterOn = False
'Screen.ActiveForm.Filter = vbNullString
Else
Screen.ActiveForm.FilterOn = False
Screen.ActiveForm.FilterOn = True
End If
I'm doing the same thing, but with a lot less code. Here is the ribbon
entry:
<group id="gExport" label="Export" >
<button id ="cmdExportToExcel"
label="Export to Excel"
size="large"
imageMso="ExportExcel"
onAction="cmdExportToExcel_OnAction"/>
</group>
Here is the callback function:
Public Sub cmdExportToExcel_OnAction(ByVal control As IRibbonControl)
RunCommand acCmdExportExcel
End Sub
There is also an acCmdExportRTF for exporting to Word.
-Tom.
Microsoft Access MVP