VBScript Excel格式化.xlsx文件
基本上我想知道如何使用VBScript设置单元格的中心对齐VBScript Excel格式化.xlsx文件,vbscript,Vbscript,基本上我想知道如何使用VBScript设置单元格的中心对齐 我一直在谷歌上搜索,似乎找不到任何有用的方法。有很多方法可以选择一个单元格或一系列单元格,但以下方法适用于单个单元格 'Select a Cell Range Range("D4").Select 'Set the horizontal and vertical alignment With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = x
我一直在谷歌上搜索,似乎找不到任何有用的方法。有很多方法可以选择一个单元格或一系列单元格,但以下方法适用于单个单元格
'Select a Cell Range
Range("D4").Select
'Set the horizontal and vertical alignment
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
水平对齐选项有xlLeft、xlRight和xlCenter
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.
将其另存为.vbs并使用命令提示符或双击运行。VBA中的VBScript或从cscript运行的外部vbs文件?酷,这正是我想要的。非常感谢,谢谢!我试图在JavaScript中使用xlCenter,但我不知道从何处获取Constants对象。这在Excel2007中非常有效。