Files
Inventaire-gestion/Scripts/set_cell_silent.vbs

69 lines
1.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
' set_cell_silent.vbs
' Usage: cscript //nologo set_cell_silent.vbs "C:\chemin\fichier.xlsm" "NomFeuille" "A1" "Valeur"
Option Explicit
Dim f, sheetName, addr, val
Dim xl, wb, ws
If WScript.Arguments.Count < 4 Then
WScript.Echo "[ERR] Args: set_cell_silent.vbs <fichier.xlsm> <feuille> <cellule> <valeur>"
WScript.Quit 1
End If
f = WScript.Arguments(0)
sheetName = WScript.Arguments(1)
addr = WScript.Arguments(2)
val = WScript.Arguments(3)
On Error Resume Next
Set xl = CreateObject("Excel.Application")
If Err.Number <> 0 Then
WScript.Echo "[ERR] Excel non disponible (" & Err.Description & ")"
WScript.Quit 1
End If
On Error GoTo 0
xl.Visible = False
xl.DisplayAlerts = False
' Désactiver macros et événements AVANT douvrir
On Error Resume Next
xl.AutomationSecurity = 3 ' msoAutomationSecurityForceDisable
xl.EnableEvents = False
xl.ScreenUpdating = False
On Error GoTo 0
On Error Resume Next
Set wb = xl.Workbooks.Open(f, False, False)
If Err.Number <> 0 Then
xl.Quit
WScript.Echo "[ERR] Ouverture classeur: " & Err.Description
WScript.Quit 1
End If
On Error GoTo 0
On Error Resume Next
Set ws = wb.Worksheets.Item(sheetName)
If Err.Number <> 0 Then
wb.Close False
xl.Quit
WScript.Echo "[ERR] Feuille introuvable: " & sheetName
WScript.Quit 1
End If
On Error GoTo 0
On Error Resume Next
ws.Range(addr).Value2 = val
If Err.Number <> 0 Then
wb.Close False
xl.Quit
WScript.Echo "[ERR] Ecriture cellule " & addr & " : " & Err.Description
WScript.Quit 1
End If
On Error GoTo 0
wb.Save
wb.Close False
xl.Quit
WScript.Quit 0