2016-07-15 50 views
1

我有下面的脚本代码,过滤器和标题设置在我第一次运行代码时不起作用,但随后使用它。MS Access FileDialog过滤器在原始加载时不起作用

有什么建议吗?

Set f = Application.FileDialog(msoFileDialogFilePicker) 

If f.Show = True Then 

With f 
    .Title = "Choose Excel File(s) to Import" 
    .Filters.Clear 
    .Filters.Add "Excel Files", "*.xlsx" 
    .AllowMultiSelect = True 

    For Each varfile In .SelectedItems 
     MsgBox "IMPORTING: " & varfile 
     tblImport = varfile 
     DoCmd.TransferSpreadsheet acImport, 10, "Parts", tblImport, True 
    Next varfile 
End With 

回答

1

调用Show方法之前设置FileDialog性能。

Set f = Application.FileDialog(msoFileDialogFilePicker) 

With f 
    .Title = "Choose Excel File(s) to Import" 
    .Filters.Clear 
    .Filters.Add "Excel Files", "*.xlsx" 
    .AllowMultiSelect = True 
    If .Show = True Then 
     For Each varfile In .SelectedItems 
      MsgBox "IMPORTING: " & varfile 
      tblImport = varfile 
      DoCmd.TransferSpreadsheet acImport, 10, "Parts", tblImport, True 
     Next varfile 
    End If 
End With