Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBScript Excel AddIn API
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 argument as required by CALL() function? and how to specify a "structure" in VBS?
 
Thanks for explanation with concrete code example.
Posted 26-Feb-12 23:43pm

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

  Print Answers RSS
0 Maciej Los 290
1 OriginalGriff 275
2 Sergey Alexandrovich Kryukov 195
3 BillWoodruff 140
4 ProgramFOX 140
0 OriginalGriff 6,524
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,218
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100