如何在使用Excel VBA连接到访问时阻止弹出窗口“是否要连接到数据库位置”?

时间:2017-05-19 12:28:14

标签: excel vba excel-vba ms-access

如何在宏询问用户是否要连接到特定数据库时阻止Excel显示弹出框?设置Application.EnableEvents似乎什么都不做。我可以从数据库中连接并检索所有数据,只是想阻止弹出框询问用户是/否/取消。

代码:

Application.EnableEvents = False
'Proceed with pulling data for the specified parameters
With wsSheet.ListObjects.Add(SourceType:=0, Source:=Array("OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;" _
    , _
     "" & DBLocation & ";Mode=Read;Extended Properties="""";" _
    , _
    "Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;" _
    , _
    "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;" _
    , _
    "Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;" _
    , _
    "Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;" _
    , "Jet OLEDB:Bypass ChoiceField Validation=False"), Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdTable
    .CommandText = Array(QueryName)
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .SourceDataFile = DBLocation
    .ListObject.DisplayName = "tbl" & SheetName
    .Refresh BackgroundQuery:=False
End With

0 个答案:

没有答案