如何将xlsm文件导入Access

时间:2014-03-12 14:38:36

标签: ms-access xlsm

如何将xlsm文件导入Access?

当然,Access会给我"请检查文件是否存在且格式是否正确"错误。我该怎么进步?

2010年为Excel和Access工作。

3 个答案:

答案 0 :(得分:1)

这是一些代码,你必须根据你的特定文件名改变它:

Sub testimport()
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "ttblTempAppend1", _
      "M:\Quality\Measurement & Evaluation\Projects\VHP\Dashboard\AAA_Rupture\ttblTempAppend1.xlsm", _
      True, "ttblTempAppend1"
End Sub

答案 1 :(得分:0)

我开始一个项目,这也将成为一个问题。我认为将启用宏的文件用作控制台而不是导入源更为实用。这是迈向这一概念的第一步:

Sub Import_Ready()

'This will take the active sheet, copy it, prepare it for import, and store it in the same directory
'as your source file. You will need to change the coding to reference a different sheet if you want
'to make this into a button or part of a process. (Or just activate the sheet you want at the start)
'The steps will be explained as though you are an evil Wizard...

    'Create Some obedient variables
    Dim ThisDirectory As String
    Dim DocumentName As String
    Dim StartingSheet As String
    Dim StartingPoint As Range

    'Reveal to those variables the nature of their purpose on this earth
    ThisDirectory = ActiveWorkbook.Path
    DocumentName = "Import Ready.xlsx"
    StartingSheet = ActiveSheet.Name
    Set StartingPoint = Selection

    'Hide the macro magic from those curious savages and ignore the ethical ramifications of what you're about to do
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    'Copy the active sheet. Now kill the living formulas and replace them with undead values that never change
    ActiveSheet.Cells.Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Name = DocumentName
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    'Take that brand new sheet and turn it into it's very own file, free from the burden of macro-enabled freedom, then put it away
    Sheets(DocumentName).Move
    ActiveWorkbook.SaveAs Filename:=ThisDirectory & "\" & DocumentName _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close

    'Go back to where you started this grand journey
    Sheets(StartingSheet).Select
    StartingPoint.Select

    'You're done! turn warnings and screen movement back on and pretend like nothing happened...
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub

对不起,我的代码段看起来并不丰富多彩。我还没弄明白怎么做。 (这是我向StackOverflow发表的第二篇文章)

答案 2 :(得分:0)

如果您使用的是Macro Builder,只需在Excel文件名末尾的“文件名”目录中添加.xlsm

例如:

文件名:C:\ Database \ Sales \ Excel_Access_DataImport.xlsm