Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
From VBS (VBScript), it is possible to call a Windows API indirectly via Excel app and one of its add-in function, CALL(), see for details the Office/Excel online help and the following MS webpage on CALL usage:

http://office.microsoft.com/en-us/excel-help/using-the-call-and-register-functions-HP005209328.aspx

Following VBS code shows an example that obtains some information by making an indirect call to a Win API function, GetTickCount():
-----------------------------------
dim tmTicks
set xlApp = CreateObject("Excel.Application")
tmTicks = xlApp.ExecuteExcel4Macro("CALL(""Kernel32"",""GetTickCount"",""J"")")
Wscript.echo "Obtained tmTicks = " & tmTicks
xlApp.Quit
set xlApp = nothing
-----------------------------------
This call is simple in that it passes in simple (-typed) args (/values) only, but I wonder how to call an API function that take more complicated arguments, e.g. structure-typed arguments - GetSystemTime() is an example which takes a structure containing 8 WORD-type elements for system time returned; in VBS, how to specify <type_text> argument as required by CALL() function? and how to specify a "structure" in VBS?

Thanks for explanation with concrete code example.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900