通过vba打开包含名称的最后添加的文件

时间:2017-10-17 17:00:21

标签: excel vba excel-vba

文件每天都会添加到一个文件夹中,它们都包含一个带有“疯狂”的名字,我需要打开最后一个才能执行我的宏。我的代码可以打开文件名包含“mad”的文件,但是它不会打开添加到文件夹中的最新文件:

  sub openfilewithnamestring
           sFound = Dir(ActiveWorkbook.Path & "\mad*.xlsb")    'should open the latest file added in the folder that constains "MAD" in the name
        If sFound <> "" Then
            Workbooks.Open Filename:=ActiveWorkbook.Path & "\" & sFound
end if

    end sub

例:
MAD0902 16.10.2017
MAD0902 17.10.2017

0 个答案:

没有答案