在我的表單訪問中,我想創建一個按鈕來瀏覽/選擇一個excel文件並以格式導入一個表格。MS Access表單按鈕,允許用戶瀏覽/選擇文件excel,然後將文件導入到表格
這是我的代碼。
'需要參考Microsoft Office 15.0 Object Library。 '
Public Function ImportDocument() As TaskImportEnum
On Error GoTo ErrProc
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.InitialFileName = "Some folder"
.Title = "Dialog Title"
With .Filters
.Clear
.Add "xlsx documents", "*.xlsx", 1
End With
.ButtonName = " Import Selected "
.AllowMultiSelect = False 'Change this to TRUE to enable multi-select
'If aborted, the Function will return the default value of Aborted
If .Show = 0 Then GoTo Leave
End With
Dim selectedItem As Variant
For Each selectedItem In fd.SelectedItems
DoCmd.TransferText acImportDelim, "Raw Data from Import_ Import Specification", "Raw Data from Import", selectedItem, True, ""
Next selectedItem
ImportDocument = TaskImportEnum.Success
Leave:
Set fd = Nothing
On Error GoTo 0
Exit Function
ErrProc:
MsgBox err.Description, vbCritical
ImportDocument = TaskImportEnum.Failure 'Return Failure if error
Resume Leave
End Function
那麼究竟是什麼問題/問題? – Andre
問題是,選擇excel文件時,它不想導入,請如果你有解決方案幫助我 –
*它不想導入*感嘆。請閱讀[問]並相應地編輯你的問題。就目前而言,它可能會被關閉。 – Andre