![](/img/trans.png)
[英]Excel dropdowns in VBA: “Unable to get the DropDowns property of the Worksheet class”
[英]Excel VBA: <Unable to get the Activate property of the Worksheet class>
我正在将xlsm模板文件下载给用户。 下载后打开文档后,在“ ThisWorkbook.Sheets(“ DataSheet”)。Activate”行中出现“无法获取Worksheet类的Activate属性”错误。 无法理解我在做什么错。
我的代码是
Sub GetData(hostName As String, id As String)
'Construct the Complete URL to get the saved view data
Dim URL As String
URL = hostName + "/Controller/Action?param=" + id
ThisWorkbook.Sheets("DataSheet").Activate
ThisWorkbook.Sheets("DataSheet").Cells.ClearContents
With ActiveSheet.QueryTables.Add( _
Connection:="URL;" + URL, _
Destination:=Range("a1")) _
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With
End Sub
有任何想法吗?
更新:仅在下载后第一次打开此错误(我从我的应用程序-启用宏的文档-XLSM下载给用户)。 一旦我关闭文档并再次打开,它就可以正常工作:(
尝试如下更改代码:
Sub GetData(hostName As String, id As String)
'Construct the Complete URL to get the saved view data
Dim URL As String
URL = hostName + "/Controller/Action?param=" + id
ThisWorkbook.Sheets("DataSheet").Cells.ClearContents ' leaves formatting
With Sheets("DataSheet").QueryTables.Add( _
Connection:="URL;" + URL, _
Destination:=Range("a1")) _
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.