Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript Excel Formatting .xlsx files

Tags:

vbscript

Basically I want to know how to set center alignment for a cell using VBScript...

I've been googling it and can't seem to find anything that helps.


1 Answers

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.

Save that as a .vbs and run it using the command prompt or double clicking.

like image 153
David J. Sokol Avatar answered Aug 09 '26 18:08

David J. Sokol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!