VBScript Excel Formatage des fichiers .xlsx
-
02-07-2019 - |
Question
En gros, je veux savoir comment définir l'alignement du centre d'une cellule à l'aide de VBScript ...
Je l'ai googlé et je n'arrive pas à trouver quoi que ce soit qui aide.
La solution
Set excel = CreateObject("Excel.Application")
excel.Workbooks.Add() ' create blank workbook
Set workbook = excel.Workbooks(1)
' set A1 to be centered.
workbook.Sheets(1).Cells(1,1).HorizontalAlignment = -4108 ' xlCenter constant.
workbook.SaveAs("C:\NewFile.xls")
excel.Quit()
set excel = nothing
'If the script errors, it'll give you an orphaned excel process, so be warned.
Enregistrez-le en tant que fichier .vbs et exécutez-le à l'aide de l'invite de commande ou en double-cliquant.
Autres conseils
Il existe de nombreuses façons de sélectionner une cellule ou une plage de cellules, mais ce qui suit fonctionnera pour une seule cellule.
'Select a Cell Range
Range("D4").Select
'Set the horizontal and vertical alignment
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Les options HorizontalAlignment sont xlLeft, xlRight et xlCenter
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow