Sub 新建文件夹 新建文件()
Dim sT As String
sT = Format(Time, "hh")
Workbooks.Add
If Dir(ThisWorkbook.Path & "\" & sT, vbDirectory) = "" Then
MkDir ThisWorkbook.Path & "\ " & sT
ActiveWorkbook.SaveAs ThisWorkbook.Path & " \ sT \ " & Format(Date, "year-mm-dd") & ".xlsx"
End If
End Sub
excel vb 我想新建个文件夹,并在该文件夹下面新建一个文件,保存。老提示出错,请高手赐教,代码如下:
答案:2 悬赏:30 手机版
解决时间 2021-01-25 19:38
- 提问者网友:抽煙菂渘情少年
- 2021-01-24 19:08
最佳答案
- 五星知识达人网友:迟山
- 2021-01-24 19:58
正确答案:
Sub 新建文件夹_新建文件()
Dim sT As String
sT = Format(Time, "hh")
Workbooks.Add
If Dir(ThisWorkbook.Path & "\" & sT, vbDirectory) = "" Then
MkDir ThisWorkbook.Path & "\ " & sT
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\ " & sT & "\" & Format(Date, "yyyy-mm-dd") & ".xls"
End If
End Sub
错误的原因:
1、Format(Date, "year-mm-dd")的格式中“年”应该为Format(Date, "yyyy-mm-dd")
2、& " \ sT \ " & 中,sT是赋值的,这样写变为文本了,应该为"\ " & sT & "\" &
3、书写中有N多的空格,程序不会自动认识 MkDir ThisWorkbook.Path & "\ " & sT的& "\ " 有空格
Sub 新建文件夹_新建文件()
Dim sT As String
sT = Format(Time, "hh")
Workbooks.Add
If Dir(ThisWorkbook.Path & "\" & sT, vbDirectory) = "" Then
MkDir ThisWorkbook.Path & "\ " & sT
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\ " & sT & "\" & Format(Date, "yyyy-mm-dd") & ".xls"
End If
End Sub
错误的原因:
1、Format(Date, "year-mm-dd")的格式中“年”应该为Format(Date, "yyyy-mm-dd")
2、& " \ sT \ " & 中,sT是赋值的,这样写变为文本了,应该为"\ " & sT & "\" &
3、书写中有N多的空格,程序不会自动认识 MkDir ThisWorkbook.Path & "\ " & sT的& "\ " 有空格
全部回答
- 1楼网友:荒野風
- 2021-01-24 20:45
你好!
Dim q
q = WorksheetFunction.Text(Now, "yyyymmddhhmmss")
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\_bak." & q
Application.Quit
仅代表个人观点,不喜勿喷,谢谢。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯