删除宏运行后建立的新连接

时间:2018-12-13 22:54:30

标签: excel vba excel-vba

我有一个excel文件,该文件当前可获取每小时指标的数据,我有10个宏按钮,这些按钮将使用vba通过网络抓取正确的信息以连接到Web网址。

每次使用任何一个宏按钮,它都会创建一个新的连接并将其添加到连接列表中。有没有办法在建立连接后删除连接?这是正在使用的代码。

谢谢您的帮助!

Sub Hour6PPR()
'
' DataPull Macro
'
Application.ScreenUpdating = False
Dim SD As Date
Dim ED As Date
Dim STS As Integer
Dim ETS As Integer
Dim STE As Integer
Dim ETE As Integer
SD = Worksheets("Variables").Range("A2").Value
ED = Worksheets("Variables").Range("A2").Value
STS = Worksheets("Variables").Range("B7").Value
ETS = Worksheets("Variables").Range("C7").Value
STE = Worksheets("Variables").Range("D2").Value
ETE = Worksheets("Variables").Range("D2").Value
Application.ScreenUpdating = False
'On Error GoTo Errorcatch

If Worksheets("1200").Visible = xlSheetHidden Then
  Worksheets("1200").Visible = xlSheetVisible
End If
 Sheets("1200").Activate
 Sheets("1200").Select
 Cells.Select
Selection.ClearContents


Sheets("1200").Select
 With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;REDACTED", _
    Destination:=Range("$A$1"))
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "2"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
Worksheets("1200").Range("E135:G150").Copy
Worksheets("PPRData").Range("W4").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Sheets("Recap").Select
End With
If Worksheets("1200").Visible = xlSheetVisible Then
  Worksheets("1200").Visible = xlSheetHidden
  End If
End Sub

0 个答案:

没有答案