判断一个文件是否存在需要用FileSystemObject:
sSourceFile="C:\Source.xls"
set fso=CreateObject("Scripting.FileSystemObject")
xlApp=CreateObject("Excel.Application")
bFileExist=fso.FileExists(sSourceFile)
if bFileExist then
set xlWorkbook=xlApp.workbooks.open(sSourceFile)
else
xlWorkbook=xlApp.workbooks.add
end if
'判断是否打开一个new file
if bFileExist then
xlWorkbook.save
else
xlWorkbook.saveas sSourceFile
end if
本文介绍了一种使用VBA代码来判断指定路径下文件是否存在的方式,并根据文件是否存在执行不同的操作,如打开现有文件或创建新文件。
887

被折叠的 条评论
为什么被折叠?



