0

如何将 xlsm 文件导入 Access?

当然,Access 给了我“请检查文件是否存在并且格式正确”的错误。我应该如何进步?

在 2010 年为 Excel 和 Access 工作。

4

3 回答 3

2

这是一些代码,您必须针对您的特定文件名进行更改,例如:

Sub testimport()
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "ttblTempAppend1", _
      "M:\Quality\Measurement & Evaluation\Projects\VHP\Dashboard\AAA_Rupture\ttblTempAppend1.xlsm", _
      True, "ttblTempAppend1"
End Sub
于 2014-03-12T15:08:36.523 回答
1

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

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 上的第二篇文章)

于 2015-04-30T20:17:04.610 回答
0

如果您使用的是宏生成器,只需在“文件名”目录中的 excel 文件名末尾添加 .xlsm

例如:

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

于 2019-07-03T03:39:06.500 回答