vba - 我在基于表格的 Excel Web 查询的 vba 代码中遇到了语法错误
问题描述
我正在尝试更新我记录的宏,以便电子表格中的行中的内容将更新 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':工作表类的粘贴方法失败”并突出显示第一个代码实例
ActiveSheet.Paste
有人可以帮我理顺吗?
解决方案
With ActiveSheet.QueryTables.Add( _
Connection:= "URL;https://rpmfind.net/linux/rpm2html/search.php?query=" & _
Range("G1").Value, Destination:=Range("$A$1"))
推荐阅读
- python - 如何修复:“不同模块中的变量不起作用”
- pandas - 如何使用每列数据从不同日期开始的数据框?
- c# - DefaultView.RowFilter 不适用于日期
- android - 有没有办法可视化片段在 android studio 检查器中加载时的样子?
- parsing - antlr 或其他工具可以为给定的语法生成有效代码吗?
- python - tkinter 在 python 3.6 上表现怪异
- angular - Angular / Facebook:应该明确提供“og:image”属性,即使可以从其他标签推断出一个值
- django - Django ModelMultipleChoiceField 不保存
- java - 当活动开始使用 Linearlayoutmanager 时,将 Recycleview 滚动到顶部位置
- c# - 参数“地址”不能为空字符串