Access 中提示選擇 Excel 電子表格?

Access 中提示選擇 Excel 電子表格?

我有一個 Microsoft Access 2007 資料庫,它使用 Excel 電子表格來追蹤兩者之間的變更。每週都會產生一個新文件。然後,我使用我為它們編寫的一些自訂 SQL 查詢對它們兩個進行比較。現在我使用連結表管理器將它們連結起來。其中有一個選項“始終提示新位置”,該選項似乎什麼都不做,但讓我目前重新選擇工作表。

無論如何,是否總是提示使用者每次開啟 Access 檔案時選擇 Excel 電子表格?

答案1

您需要設定一個引用,VBA (tools-References)然後尋找並點擊"Microsoft Office"以使用它。

Dim myDialog As FileDialog
Dim strFile As String
Dim strSearchPath as string
Dim vrtSelectedItem As Variant
Set myDialog = Application.FileDialog(msoFileDialogOpen)

With myDialog
    .AllowMultiSelect = True
     .Filters.Add "Excel Files", "*.xls", 1
    .Title = "Select the file"
    .InitialFileName = strSearchPath
    If .Show = -1 Then   
        For Each vrtSelectedItem In .SelectedItems         
          ImportIt (vrtSelectedItem)
        Next vrtSelectedItem
    Else
        'The user pressed Cancel.
    End If
   Set myDialog = Nothing
End With

筆記:還沒有測試過。

相關內容