2014-03-12 145 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」,對嗎?)如果定期完成,在關閉之前調用該子將特別方便。 –

相關問題