VBA 每日文件按日期打包存放

每天省出1小时,换个好心情

1.判断是否存在tempfolder (过渡文件夹)
2.不存在 则在目标目录下新建文件夹tempfolder

在网上看到一种更简单的方法

if dir("e:\定单计划\月度定单\日计划\") ="" then MkDIr "e:\定单计划\月度定单\日计划\"

3.将excel文件复制到tempfolder,本人筛选报表的关键字是"liyi",筛选条件
4.用name 对tempfolder 重命名

操作之前

Sub 报表打包()
On Error Resume Next
Dim a As String
a = "C:\Users\Administrator\Desktop\201605报表\tempfolder"
If Len(Dir(a)) = Empty Then
    
    Set tempfolder = CreateObject("scripting.filesystemobject")

    tempfolder.createfolder ("C:\Users\Administrator\Desktop\201605报表\tempfolder")

Else
     
     MsgBox "tempfolder已经存在!"
     
End If

Dim foldername As String

Set fs = CreateObject("Scripting.FileSystemObject")
  
fs.copyfile "C:\Users\Administrator\Desktop\每日报表\*liyi*.xls*", "C:\Users\Administrator\Desktop\201605报表\tempfolder", True

 '复制报表到tempfolderN
    yue = Month(Date)
    ri = Day(Date)

Name "C:\Users\Administrator\Desktop\201605报表\tempfolder" As "C:\Users\Administrator\Desktop\201605报表\0" & yue & ri
'文件夹更名

End Sub

运行宏之后的结果:


posted @ 2016-05-23 17:16  li_volleyball  阅读(552)  评论(0编辑  收藏  举报