0
感謝您的幫助和支持。我對excel很陌生,這可能是一個基本問題。Excel宏錯誤:「錯誤1004:應用程序違反或對象定義錯誤」
我想運行一個宏來將訪問查詢結果導出到excel。我計劃自動運行宏,每週運行一次,以便將結果導出到相同的excel中,但不同的標籤命名爲date。我已經記錄了一個宏來這樣做,並嘗試第二次運行該宏,並拋出錯誤以下。
"Error 1004: application defied or object defined error"
,並指向這行代碼.ListObject.DisplayName = "Table_Speed.accdb_16"
Sub Macro_Query3()
Dim ws As Worksheet
For Each ws In Worksheets
If Left(ws.Name, 8) = Format(Now(), "mm-dd-yy") Then x = x + 1
Next
Sheets.Add.Name = Format(Now(), "mm-dd-yy") & " (" & x + 1 & ")"
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(_
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=C:\s" _
, _
"peed\Speed.accdb;Mode=Share Deny Write;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=Fal" _
, _
"se;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"), Destination:= _
Range("$A$1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array("Final")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"C:\speed\Speed.accdb"
.ListObject.DisplayName = "Table_Speed.accdb_16"
.Refresh BackgroundQuery:=False
End With
End Sub
任何幫助將不勝感激。
感謝您的快速更新,會發生什麼。它仍然拋出同樣的錯誤。當我評論該行時,它按照我的要求工作,但我不確定是否可以對此行進行評論。 –
使用.Name代替.DisplayName怎麼樣? – dendarii