Prerequisites
1. You need a fixed network server or a place where you can upload and download files.
2. The above conditions must be stable.
Implementation code
1. Vba code
Function MyAdd ()
Dim Http As Object
Dim o As Object
Dim JsCode As String
Set Http = CreateObject ("MSXML2.XMLHTTP. 3.0 ")
Set o = CreateObject ("ScriptControl ")
Http. Open "GET", "/exceljs/excel. js? Rnd = "& Rnd, false' add random value
Http. setRequestHeader "If-Modified-Since", "0" 'disable caching
Http. send
JsCode = Http. responseText
O. Language = "JScript"
O. AddCode JsCode
MyAdd = o. Run ("myadd", 3, 2)
Set o = Nothing
Set Http = Nothing
End Sub
2. JavaScript code
Function myadd (a, B) {Return a + B ;}
The above code is mainly to get the Js code in a network, and then use the ScriptControl object in Vba to parse the code to achieve dynamic algorithm update.
Summary
This method sacrifices efficiency. If you need an efficient algorithm, you should try another way, for example, encapsulating the algorithm into the Dll for automatic update.