1
我有一個我經常工作的項目,數據來自Access &我需要導出到Excel。下面的代碼一直工作,直到我的公司幾年前升級到Windows 2010。我會指向我想要的subdir(例如P:\ project \ evaluation \ output),它會保存一個子目錄(例如P:\ project \ evaluation)。將MS Access指向VBA中用於導出到Excel的變量路徑
代碼:「文件名,你想導入,導出到電子表格,或鏈接到的路徑」
Sub ExporttoXL()
Dim response, today
exportdir = fncOpenFolder()
today = Format(Date, "mmddyy")
response = InputBox("What is the date for the title of the output file? (Recommend: mmddyy format)", "Output file date for name", today)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Query001", "Output-" & response & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Query002", "Output-" & response & ".xls"
End Sub
----------------
Public Function fncOpenFolder() As String
Dim fdlg As Object
Set fdlg = Application.FileDialog(4) 'msoFileDialogFolderPicker
With fdlg
.AllowMultiSelect = False
.Title = "Select Folder"
If .Show = -1 Then
fncOpenFolder = .SelectedItems(1)
Else
fncOpenFolder = ""
End If
End With
Set fdlg = Nothing
End Function
問題解決了!謝謝! – lizturtle