Excel 如何在公共函数中实现Application.Caller
下面的函数取F列(货币代码)中的值,并返回H列中的函数输出(相当于输入的20美元) 问题是,当我将方程式向下拖动到H列(从H2开始)时,方程式没有更新F列中的值 示例:H2=Oanda(F2)Excel 如何在公共函数中实现Application.Caller,excel,vba,internet-explorer,web-scraping,automation,Excel,Vba,Internet Explorer,Web Scraping,Automation,下面的函数取F列(货币代码)中的值,并返回H列中的函数输出(相当于输入的20美元) 问题是,当我将方程式向下拖动到H列(从H2开始)时,方程式没有更新F列中的值 示例:H2=Oanda(F2) 当我向下拖动它(比如说F10)时,方程给出了Oanda(F2)的输出,而不管F3-F10的值是多少。我需要一些帮助来实现Application.Caller功能 Option Explicit Public Function Oanda(ConvertWhat As String) 'Referenc
当我向下拖动它(比如说F10)时,方程给出了Oanda(F2)的输出,而不管F3-F10的值是多少。我需要一些帮助来实现Application.Caller功能
Option Explicit
Public Function Oanda(ConvertWhat As String)
'References
' Microsoft XML, vs.0
' Microsoft Internet Controls
' Microsoft HTML Object Library
Dim Conversion As String
Conversion = ThisWorkbook.Sheets("Employee").Range("F" & ActiveCell.Row).Value2
Dim IE As New InternetExplorer
'IE.Visible = True
IE.Navigate "https://www.oanda.com/currency/converter?quote_currency=USD&base_currency=" & Conversion
Do
DoEvents
Loop Until IE.ReadyState = ReadyState_Complete
Dim Doc As HTMLDocument
Set Doc = IE.Document
Dim Ans As String
Ans = Trim(Doc.getElementsByTagName("tbody")(2).innerText)
Dim AnsExtract As Variant
AnsExtract = Split(Ans, " ")
Oanda = AnsExtract(4) * 20
End Function
使用传递到函数中的变量
Option Explicit
Public Function Oanda(ByVal ConvertWhat As String) As Double
'References
' Microsoft XML, vs.0
' Microsoft Internet Controls
' Microsoft HTML Object Library
Dim IE As New InternetExplorer
'IE.Visible = True
IE.Navigate "https://www.oanda.com/currency/converter?quote_currency=USD&base_currency=" & ConvertWhat
Do
DoEvents
Loop Until IE.ReadyState = ReadyState_Complete
Dim Doc As HTMLDocument
Set Doc = IE.Document
Dim Ans As String
Ans = Trim$(Doc.getElementsByTagName("tbody")(2).innerText)
Dim AnsExtract As Variant
AnsExtract = Split(Ans, " ")
Oanda = AnsExtract(4) * 20
End Function
输出不是问题所在。问题是函数无法识别调用函数的单元格,因此在拖动(或复制和粘贴)时返回相同的值。它仅在手动输入公式时识别呼叫单元。如果F2=EUR,则L2=16.99。如果F3=美元,则L3=20。如果我在L2中键入函数,然后向下拖动到L3,两个单元格的值都是16.99。