【问题标题】:Execute Macro after data refresh数据刷新后执行宏
【发布时间】:2020-05-05 17:27:32
【问题描述】:

下面的宏使用超链接函数更新 A 列。

在我的查询/数据源上单击数据刷新后如何运行它?

我尝试在我的工作表上写一个更改条件。

Sub InsertHyperlinkFormulaInCell()

currentRow = 2   
While Cells(currentRow, 2) <> "" 'check whether Column B is empty, stop if it is
ActiveWorkbook.Worksheets("Query").Cells(currentRow, 1) = "=HYPERLINK(CONCAT(X" & currentRow & ",B" & 
currentRow & "),W" & currentRow & ")"
currentRow = currentRow + 1
Wend

End Sub

【问题讨论】:

标签: excel vba


【解决方案1】:

不要手动刷新您的查询,而是从宏中执行,然后继续您的代码。

Sub InsertHyperlinkFormulaInCell()

Query.QueryTable.Refresh

'rest of your code here

End Sub

【讨论】:

  • 谢谢你的工作,我还添加了一行来停用后台刷新选项。非常感激! ActiveWorkbook.Connections("query1").OLEDBConnection.BackgroundQuery = False ActiveWorkbook.Connections("query1").Refresh
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 2020-07-29
  • 2013-09-05
  • 2017-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多