用VBA怎样在D盘上新建一个指定名称文件夹,且在文件夹下建一个指定文件名的EXCEL文件
1个回答
2011-06-23
展开全部
假设指定路径是“D:\”,指定文件夹名称为“NEWFOLDER”,指定文件名是“MYBOOK.XLS”
主要VBA语句如下:
myfld="D:\NEWFOLDER\"
mybuk="MYBOOK.XLS"
fName=myfld+mybuk
Set s = CreateObject("Scripting.FileSystemObject")
On Error GoTo e1
s.CreateFolder (myfld)
Workbooks.Add (xlWBATWorksheet)
ActiveWorkbook.SaveAs Filename:=fName
On Error GoTo 0
ActiveWorkbook.Close False
Set s = Nothing
Exit Sub
e1:
MsgBox "文件夹或文件[" + fName + "]已存在或创建错误!!!"
Resume Next
主要VBA语句如下:
myfld="D:\NEWFOLDER\"
mybuk="MYBOOK.XLS"
fName=myfld+mybuk
Set s = CreateObject("Scripting.FileSystemObject")
On Error GoTo e1
s.CreateFolder (myfld)
Workbooks.Add (xlWBATWorksheet)
ActiveWorkbook.SaveAs Filename:=fName
On Error GoTo 0
ActiveWorkbook.Close False
Set s = Nothing
Exit Sub
e1:
MsgBox "文件夹或文件[" + fName + "]已存在或创建错误!!!"
Resume Next
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询