![](/img/trans.png)
[英]How to create a function to hide rows based on a cell value in VBA EXCEL
[英]Excel VBA - Create rows for each updated value in DDE link cell
可以说单元格A1有一个DDE链接“ = dde(realtime_stock_price)。每次更新时如何将值发送到列的新行?Change()函数不起作用,因为它不是用户进行更改。尝试了Calculate()函数,但不太确定如何实现它。
我不熟悉公式“ = dde()”。 但是,您可以只创建自己的dde函数来调用事件代码...
Public Function dde2(ByVal app as string,ByVal topic as string,ByVal item as string) as variant
with Application
channelNumber = .DDEInitiate(app,topic)
dde2 = .DDERequest(channelNumber, "Topics")
.DDETerminate(channelNumber)
end with
on error resume next 'incase macro doesn't exist
Application.run "dde2_postExec", dde2
on error goto 0
End Function
Sub dde2_postExec(ByVal message as string)
'do stuff...
end sub
根据此问题 ,传递给=DDE()
的字符串是"Service|Topic!Item"
。 或者在我们的示例中: "App|Topic!Item"
,可以轻松地从字符串中提取它。 但是请注意, DDE()
不是excel的本机函数 。 因此,我们不太可能知道DDE()
如何工作以提供一个干净的解决方案。
根据您的评论,假设DDE正在流式传输"12...13...14..."
并且您想输出B1 = 12
, B2=13
和B3=14
。 您的代码将如下所示:
Sub dde2_postExec(ByVal message as string)
dim v as variant: v=split(message,"...")
for i = 1 to ubound(v)-1
range("B" & i).value = v(i)
next
end sub
但是请注意,如果将其作为公式调用,则可能无法正常工作。 VBA运行时的设计使得在评估forumla时,除了调用它们的单元格之外,它们无法将值写入工作表中的单元格。 因此,您可能不得不使用工作表事件而不是使用公式的calculate事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.