2014-03-12 101 views
0

如何将xlsm文件导入到Access中?如何将xlsm文件导入到Access

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

在2010年为Excel和Access工作。

+0

如果您担心导入文件一次,您可以简单地将其扩展名更改为.xlsx – parakmiakos

+0

我的道歉。缺乏信息的问题。这是需要每周发生30次的事情。因此,希望写一个宏或某事analagous。 – jph

回答

1

下面是一些代码,你就必须改变它为特定文件名,例如:

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

感谢您的代码!我通过替换文件位置尝试了它,但它不起作用。我必须更换其他东西吗? (“ttblTempAppend1”?) – jph

+0

是的。这是您要将数据导入到的表的名称。查看http://msdn.microsoft.com/en-us/library/office/ff844793(v=office.15).aspx查看所有必需的输入。 –

+0

感谢您的帮助! – jph

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)

+1

Hi @anənimədē,你在问一个问题,还是回答原来的问题? –

+0

主要是后者。我与OP有关并提出了一个可行的解决方案(这对我的需求起作用)。也就是说,使用.xlsm在同一个目录中创建一个.xlsx文件。我很肯定这对jph也是很好的。 (我假设你的首字母代表“Jazz Player Hottie”,对吗?)如果定期完成,在关闭之前调用该子将特别方便。 –

相关问题