VBS create Excel

自留地
Dim xlApp
Dim xlWorkBook
Dim xlWorkSheet
Function CreateExcel(ExcelPath)
	Set xlApp=createobject("Excel.Application")
	sSourceFile=ExcelPath
	Set fso=createobject("Scripting.filesystemobject")
	'判断文件是否已存在
	bFileExist=fso.FileExists(sSourceFile)
	if bFileExist then
		'   如果存在则打开
		set xlWorkbook=xlApp.Workbooks.open(sSourceFile)
		xlApp.visible=True
	else
		set xlWorkBook=xlApp.Workbooks.Add
		set xlWorkSheet=xlWorkBook.Activesheet
		xlApp.visible=True
		xlWorkBook.saveas ExcelPath
	End if
End Function

CreateExcel "c:\test.xls"	

你可能感兴趣的:(Excel,VBScript)