VBA 中的 Command_button 与具有指定宏的形状

问题描述

我正在尝试编写一个脚本,用于从用户表单内的网络中提取数据。我在 Excel (2019) 中使用“从 Web 获取数据”选项。当我手动刷新数据时,甚至当我使用分配了 Autoshape 的宏进行刷新时,数据都会更新。但是,我已经从宏中为我的用户窗体中的 CommandButton 粘贴了相同的代码。我的目的是在单击 CommandButton 时刷新数据。但是当我点击它时,后台查询会继续运行并且不会终止。

这是一个宏的代码(用于刷新数据自动整形)

Sub refresh()
ActiveWorkbook.Connections("Query - stocklist").refresh
End Sub

这是我的用户表单中的代码(用于 REFRESH 和 GET 命令按钮)。 GET 按钮执行一种 Vlookup 并且工作正常。

Private Sub cmd_refresh_Click()
    ActiveWorkbook.Connections("Query - stocklist").refresh
End Sub


Private Sub cmd_get_Click()
txt_script.Text = UCase(txt_script.Text)
For Each cell In Range("Table_stock[Symbol]")
'For Each cell In Range("A1:I220")
    If cell = txt_script.Value Then
   txt_ltp.Value = cell.Offset(0,4)
    End If
Next cell

End Sub

有什么建议吗?

附图excel template showing user form and macro button

更清楚

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...