3
쿼리 테이블을 만드는 코드가 있습니다. 그것을 생성 한 후 원하는 데이터를 꺼낸 다음 해당 쿼리를 완료합니다. 나는 그것을 즉시 지우고 싶기 때문에 공간을 차지하지 않는 많은 쿼리 테이블을 원하지 않는다. 내가 사용한다Excel VBA를 통해 워크 시트 쿼리를 완전히 삭제하십시오.
QueryTables.Delete
ActiveWorkbook.Connections.Item(i).Delete
문제는 쿼리 테이블 연결이 여전히 존재한다는 것입니다. 따라서 같은 이름을 사용하여 다른 쿼리를 만들려고하면 이미 존재한다는 것을 알 수 있습니다.
해당 테이블의 레코드가 완전히 사라 졌으면합니다.
Sub Macro8()
Dim currency1 As String
Dim currency2 As String
currency1 = ActiveSheet.Range("currency1")
currency2 = ActiveSheet.Range("currency2")
Range("clear").Select
Selection.ClearContents
ActiveWorkbook.Queries.Add Name:="FXFWD", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""http://www.investing.com/currencies/" & currency2 & "-" & currency1 & "-forward-rates""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{"""", type text}, {""Name"", type text}, {""Bid"", type number}, {""Ask"", type number}, {""High"", type number}, {""Low"", type number}, {""Chg."", type number}, {""Time""," & _
" type text}})," & Chr(13) & "" & Chr(10) & " #""Removed Columns"" = Table.RemoveColumns(#""Changed Type"",{""""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Removed Columns"""
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = "Book1"
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=FXFWD" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [FXFWD]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "FXFWD"
.Refresh BackgroundQuery:=False
End With
Sheets("Book1").Rows("1:33").Copy
Sheet1.Rows("18").PasteSpecial xlPasteValues
Sheets("Book1").Select
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim con As Object
Dim ws As Worksheet
Dim qryT As QueryTable
For Each con In ThisWorkbook.Connections
con.Delete
Next con
For Each ws In ThisWorkbook.Worksheets
For Each qryT In ws.QueryTables
qryT.Delete
Next qryT
Next ws
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Sheet1.Select
End Sub
왜 직접 그 연결을 변경 : 여기
내 코드? 그것을 삭제하고 다시 만드는 대신에, 직접적인 변화는 한 단계에서 그것을 할 것입니다 ... –더크 감사합니다. 이것은 좋은 생각이고 나는 지금 당장 그것을하려고 노력할 것입니다 :) –