[英]Ms Access: Export subform to Excel, remove hidden columns
I have a form with a filtered subform in MS Access with checkboxes controlling the hidden columns. 我在MS Access中有一个带有筛选子表单的表单,带有控制隐藏列的复选框。 I managed to export the filtered subform to excel, but the hidden columns are kept and shown on the excel file.
我设法将过滤后的子表单导出到excel,但是隐藏的列被保留并显示在excel文件中。
How can I only export the visible columns to the excel file? 如何仅将可见列导出到excel文件?
I am using MS-Access 2007. My code to export so far: 我正在使用MS-Access2007。到目前为止,我要导出的代码:
Private Sub btn_export_Click()
On Error GoTo errHandler
Dim qdf As QueryDef
DoCmd.DeleteObject acQuery, "qryTemp"
Set qdf = CurrentDb.CreateQueryDef("qryTemp", Me.Results_Subform.Form.RecordSource)
DoCmd.OutputTo acOutputQuery, "qryTemp", acFormatXLS, "C:\TEST_Export.xls", True
exitHandler:
Exit Sub
errHandler:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
Resume exitHandler
End If
End Sub
Something like so... 像这样...
Dim x As Excel.Application
Dim r As Recordset
Dim w As Excel.Worksheet
Dim l As Long
Dim c As New Collection
Set r = Me.Recordset
Set x = New Excel.Application
x.Visible = 1
If x.Workbooks.Count = 0 Then x.Workbooks.Add
Set w = x.Worksheets(1)
For l = 0 To r.Fields.Count - 1
If Me.Controls(r.Fields(l).Name).ColumnHidden Then
c.Add l + 1
End If
w.Range("a1").Offset(0, l).Value = r.Fields(l).Name
Next l
w.Range("a2").CopyFromRecordset r
For Each i In c
w.Columns(i).Hidden = True
Next i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.