2种条件同时执行-Excel宏

时间:2019-06-14 11:03:27

标签: excel vba

我试图根据两个条件使我的宏在文件中运行,其代码如下:

Sub RefreshYesterday()
    Dim folderPath As String
    Dim filename As String
    Dim wb As Workbook
    FullName = ActiveWorkbook.FullName
    Name = ActiveWorkbook.Name
    slice = Len(FullName) - Len(Name)
    FileDate = Left((FileDateTime(FullName)), 10)
    Application.AskToUpdateLinks = False
    Application.DisplayAlerts = False

    folderPath = (Left(FullName, slice))

    If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

    filename = Dir(folderPath & "*.xlsb")
    **Do While filename <> "" And FileDate <> Date**
      Application.ScreenUpdating = False

        Set wb = Workbooks.Open(folderPath & filename)

        'Call a subroutine here to operate on the just-opened workbook
        Call Mymacro
        DoEvents


        filename = Dir
    Loop
    Application.ScreenUpdating = True
    Application.AskToUpdateLinks = True
    Application.DisplayAlerts = True
  MsgBox "Update Complete " + GetXLUserName
End Sub

然而,应该忽略最后更新日期为今天的文件的do while条件不起作用,它适用于每个文件夹,而不考虑日期,有什么建议吗?

执行文件名<>“”和FileDate <>日期

0 个答案:

没有答案