![](/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.