Excel automatically updates algorithms using javascript

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.