cs_JMO
Messages postés
1854
Date d'inscription
jeudi 23 mai 2002
Statut
Membre
Dernière intervention
24 juin 2018
27
14 mars 2006 à 21:25
Bonsoir,
J'ai trouvé, ce week-end, sur ce Forum, plusieurs scripts en VBS qui utlisent des APIs via EXcel/VBA.
Exemple:
Set sh = WScript.CreateObject("WScript.Shell")
on error resume next
sh.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Security\accessVBOM",1,"REG_DWORD"
on error goto 0
Set exl = WScript.CreateObject("excel.Application")
exl.Visible = false
set fichxl=exl.workbooks.add
Set mdle = fichxl.VBProject.VBComponents.Add(1)
mdle.CodeModule.InsertLines 1, "Declare Function GetWindowDC Lib ""user32"" (ByVal hwnd As Long) As Long"
mdle.CodeModule.InsertLines 2, "Declare Function Ellipse Lib ""gdi32"" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long"
mdle.CodeModule.InsertLines 3, "Declare Sub Sleep Lib ""kernel32"" (ByVal dwMilliseconds As Long)"
mdle.CodeModule.InsertLines 4, "Sub bulles()"
mdle.CodeModule.InsertLines 5, "For num = 1 To 1000"
mdle.CodeModule.InsertLines 6, "xx = 1000 * Rnd()"
mdle.CodeModule.InsertLines 7, "yy = xx * Rnd()"
mdle.CodeModule.InsertLines 8, "diam = 100 * Rnd"
mdle.CodeModule.InsertLines 9, "Ellipse GetWindowDC(0), xx, yy, xx + diam, yy + diam"
mdle.CodeModule.InsertLines 10, "Sleep 20"
mdle.CodeModule.InsertLines 11, "Next"
mdle.CodeModule.InsertLines 12, "End Sub"
exl.Run "bulles"
fichxl.close(false)
exl.quit
Set fichxl=nothing
set mdle=nothing
set exl=nothing
set sh=nothing