简体   繁体   English

MS Access忽略了我的VBA代码以在没有标题的情况下进行导出

[英]MS Access is ignoring my VBA code to export without headers

I have made a snippet of VBA code which exports two tables from MS Access 2010 into a new xlsx spreadsheet. 我编写了一段VBA代码,该代码将MS Access 2010中的两个表导出到新的xlsx电子表格中。 I manually delete the spreadsheet before I run the code again. 在再次运行代码之前,我手动删除了电子表格。

The field names from my tables are exported into the spreadsheet as cell data. 我表中的字段名称作为单元格数据导出到电子表格中。 Which I DONT want. 我不想要的。

In the code same below I've set one export property to true and one to false just to show it is exporting the same way for both. 在下面的相同代码中,我将一个export属性设置为true,将一个export属性设置为false只是为了表明它对两者的导出方式相同。 I have tried both false and both true as well. 我也尝试过错误和真实。

public sub output

outputFileName as string

outputFileName = "J:\My Documents\testmycode.xlsx"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Example1 Table", outputFileName, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Example 2 Table", outputFileName, True

end sub

Any help is gratefully recieved! 感谢您的任何帮助!

This argument is not used by TransferSpreadsheet when exporting to EXCEL; 导出到EXCEL时,TransferSpreadsheet不使用此参数; it always exports the field names regardless of what you put for this argument in your code or macro. 无论您在代码或宏中为该参数添加了什么内容,它始终会导出字段名称。 This argument works only for imports. 此参数仅适用于导入。

Maybe this would do it for you. 也许这会为您做。

Public Function DeleteRowInExcel()
On Error GoTo Err_DeleteRowInExcel

    Dim xlApp As Excel.Application
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim MyFileName As String

    MyFileName = "c:\temp\MyOutputFile.xls"

    Set xlApp = CreateObject("Excel.Application")
    Set wb = xlApp.Workbooks.Open(MyFileName)
    Set ws = wb.Sheets(1)

    ws.Cells(1, 1).EntireRow.Delete

    wb.Save

Exit_DeleteRowInExcel:
        'Close Excel
    wb.Close savechanges:=False
    xlApp.Quit
    Set xlApp = Nothing
    Set wb = Nothing
    Set ws = Nothing
    Exit Function

Err_DeleteRowInExcel:
    MsgBox Err.Number & ", " & Err.Description, , "Error"
    Resume Exit_DeleteRowInExcel

End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM