我在基于表

时间:2018-06-17 19:10:35

标签: excel vba excel-vba web

我正在尝试更新我记录的宏,以便电子表格中的行内容将更新Web查询目标,但遇到了一些错误。我已对其中几个进行了排序,但当前问题是运行时错误。以下是我的查询代码:

Sub GetAllPkgInfo()

  Sheets("AllPkgs").Select
  Range("A2").Select

  Do Until ActiveCell.Value = ""
    Call PkgInfo1
  Loop


End Sub



Sub PkgInfo1()
'
' PkgInfo1 Macro
' Import RHEL package information from RPMFind
'
' Keyboard Shortcut: Ctrl+Shift+D
'
    Selection.Copy
    Sheets("WebQuery").Select
    ActiveSheet.Cells.Clear
    Range("$G$1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    With ActiveSheet.QueryTables.Add( _
    Connection:="URL;https://rpmfind.net/linux/rpm2html/search.php?query=" & _
       Range("$G$1").Value, Destination:=Range("$A$1"))
        .CommandType = 0
        .Name = "search.php?query=abrt_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
    End With
    ActiveCell.Offset(1, -5).Range("A1").Select
    Selection.Copy
    Sheets("AllPkgs").Select
    ActiveCell.Offset(0, 1).Range("CombinedPackages[[#Headers],[Column1]]").Select
    ActiveSheet.Paste
    Sheets("WebQuery").Select
    ActiveCell.Cells.Select
    Application.CutCopyMode = False
    Selection.QueryTable.Delete
    Selection.ClearContents
    Sheets("AllPkgs").Select
    ActiveCell.Offset(1, -1).Range("CombinedPackages[[#Headers],[Column1]]").Select
End Sub

我收到的错误消息指出"运行时错误' 1004&#39 ;:工作表类的粘贴方法失败"并突出显示

的第一个代码实例
    ActiveSheet.Paste

有人可以帮我理顺吗?

1 个答案:

答案 0 :(得分:0)

With ActiveSheet.QueryTables.Add( _
    Connection:= "URL;https://rpmfind.net/linux/rpm2html/search.php?query=" & _
       Range("G1").Value, Destination:=Range("$A$1"))