我试图在VBA中杀死一个* .mdb文件,但是我在Excel中使用了Permission被拒绝。
If (fso.FileExists(tablepath & tablename & ".mdb")) Then
Kill tablepath & tablename & ".mdb"
End If
我想导入它然后将其删除。我认为以下导入一旦导入就关闭了与mdb的连接,显然不是。
如何关闭连接?
这是MS Excel 2010 32位。
With Workbooks(new_workbook_name).Sheets(FolderName & " Detail").ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=" & tablepath & tablename & ".mdb;" _
, _
"Mode=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:D" _
, _
"atabase Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Glob" _
, _
"al Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=Fals" _
, _
"e;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Supp" _
, "ort Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False"), _
Destination:=Range("A1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array(tablename)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
tablepath & tablename & ".mdb"
.ListObject.DisplayName = "Table_" & tablename
.Refresh BackgroundQuery:=False
End With
答案 0 :(得分:1)
在字符串QueryTable之后添加以下行:
.MaintainConnection = False
在该情况下,在查询之后释放连接。默认值为True。