VBScript to center Text

J

jonezn

I can use this to open the csv file and autofit/sort it. Now how do you
center the entire sheet not just one cell?

Const xlAscending = 1
Const xlYes = 1

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = _
objExcel.Workbooks.Open("h:\Test.csv")


Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange1 = objWorksheet.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange1.Sort objRange2, xlAscending, , , , , , xlYes

Set objRange = objExcel.Columns("A:K").AutoFit

this line does a cell.
objWorksheet.Cells(1, 7).HorizontalAlignment = -4108

how can you do the entire workbook?
 
J

Jim Cone

You can do the entire sheet with...
objWorksheet.Cells.HorizontalAlignment = -4108

--or-- maybe this would be more efficient...
objRange1.Cells.HorizontalAlignment = -4108
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"jonezn"
<[email protected]>
wrote in message
I can use this to open the csv file and autofit/sort it. Now how do you
center the entire sheet not just one cell?

Const xlAscending = 1
Const xlYes = 1

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = _
objExcel.Workbooks.Open("h:\Test.csv")


Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange1 = objWorksheet.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange1.Sort objRange2, xlAscending, , , , , , xlYes

Set objRange = objExcel.Columns("A:K").AutoFit

this line does a cell.
objWorksheet.Cells(1, 7).HorizontalAlignment = -4108

how can you do the entire workbook?
 
G

Gary''s Student

If
objWorksheet.Cells(1, 7).HorizontalAlignment = -4108
works on a single cell then

objWorksheet.Cells.HorizontalAlignment = -4108
should work on all the cells
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top