Files
Inventaire-gestion/Scripts/set_cell_silent.vbs

71 lines
1.4 KiB
Plaintext

Option Explicit
Dim xl, wb
Dim filePath, sheetName, cellAddress, cellValue
If WScript.Arguments.Count < 4 Then
WScript.Echo "[ERR] Usage : set_cell_silent.vbs fichier.xlsm feuille cellule valeur"
WScript.Quit 1
End If
filePath = WScript.Arguments(0)
sheetName = WScript.Arguments(1)
cellAddress = WScript.Arguments(2)
cellValue = WScript.Arguments(3)
On Error Resume Next
Set xl = CreateObject("Excel.Application")
If Err.Number <> 0 Then
WScript.Echo "[ERR] Creation Excel : " & Err.Description
WScript.Quit 1
End If
xl.Visible = False
xl.DisplayAlerts = False
xl.EnableEvents = False
xl.AskToUpdateLinks = False
xl.AutomationSecurity = 3
Err.Clear
Set wb = xl.Workbooks.Open(filePath, 0, False)
If Err.Number <> 0 Then
WScript.Echo "[ERR] Ouverture classeur: " & Err.Description
xl.Quit
Set xl = Nothing
WScript.Quit 1
End If
Err.Clear
wb.Worksheets(sheetName).Range(cellAddress).Value = cellValue
If Err.Number <> 0 Then
WScript.Echo "[ERR] Ecriture cellule: " & Err.Description
wb.Close False
xl.Quit
Set wb = Nothing
Set xl = Nothing
WScript.Quit 1
End If
Err.Clear
wb.Save
If Err.Number <> 0 Then
WScript.Echo "[ERR] Sauvegarde: " & Err.Description
wb.Close False
xl.Quit
Set wb = Nothing
Set xl = Nothing
WScript.Quit 1
End If
Err.Clear
wb.Close False
Set wb = Nothing
xl.Quit
Set xl = Nothing
WScript.Quit 0