Export to excel - datasheet captions and visible columns only

lundi 13 avril 2015

I have the following which exports to excel.




Code:



Sub test7()

Dim rs As Recordset

Dim intCount As Integer

' Create the Excel object

Set mobjXl = CreateObject("Excel.Application")



' Fetch the recordset

Set rs = Forms!OrdersOptions!OrdersOptionsList.Form.RecordsetClone 'name of form and subform



With mobjXl

' Add a workbook and turn of Excel updates

.ScreenUpdating = True

.Visible = False

.Workbooks.Add

.DisplayAlerts = True



' Add the column headers

For intCount = 0 To rs.Fields.Count - 1

.Cells(1, intCount + 1).Value = rs.Fields(intCount).Name

Next intCount





' Dump the recordset to Excel

.Range("A2").CopyFromRecordset rs

.Visible = True



End With

' Add your error handler

End Sub



What I would like is to export it but have the column headings as the datasheet captions and only export visible columns.



I can manually add in scripts to rename the column headings and delete the columns that I don't want, but obviously if there is a script that can already do this it would be preferable.

Export to excel - datasheet captions and visible columns only

0 commentaires:

Enregistrer un commentaire

Labels