检查文件夹名称变量中的4个子文件夹出口

时间:2013-09-30 16:46:49

标签: vba

我有一个每周日创建索引的程序。在星期日,创建一个以.001后缀的日期命名的文件夹。格式为YYYYMMDD.001

实施例: 20130929.001

在该文件夹中,创建了4个文件夹,它们始终具有相同的名称: TEXT1 TEXT2 TEXT3 文本4

我希望有一个脚本验证是否正在创建该文件夹,如果其中一个子文件夹未退出,则会发送一封电子邮件。

我们的想法是安排脚本在同一天运行,但应在创建文件夹之后运行。如果预期的文件夹退出,则会发送通知。

我的问题是处理变量日期路径的第一部分和最后一部分是一致的,但带日期的日期文件夹将每周更改。

N:\应用\ WORLDOX \ isysdb \ drive_n \文本\ 0.001 \ TEXT1

任何建议都将不胜感激。

谢谢, ELM

1 个答案:

答案 0 :(得分:0)

此代码检查文件夹是否存在。如果没有,将发送邮件。

Sub TestFolder()

    Dim fso As Object, MyFolder As String
    Dim folder1 As String, folder2 As String, folder3 As String, folder4 As String
    Set fso = CreateObject("Scripting.FileSystemObject")

    MyFolder = "C:\ YYYYMMDD.001\"

    folder1 = MyFolder & "TEXT1"
    folder2 = MyFolder & "TEXT2"
    folder3 = MyFolder & "TEXT3"
    folder4 = MyFolder & "TEXT4"

    If fso.FolderExists(folder1) = False Then
          SendMail "TEXT1"
    ElseIf fso.FolderExists(folder2) = False Then
         SendMail "TEXT2"
    ElseIf fso.FolderExists(folder3) = False Then
          SendMail "TEXT3"
    ElseIf fso.FolderExists(folder4) = False Then
          SendMail "TEXT4"
    End If


End Sub


Sub SendMail(folderName)

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant


    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1
    Set Flds = iConf.Fields

    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ddddd"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With

    With iMsg

        Set .Configuration = iConf
        .To = "test@gmail.com"
        .From = "test@gmail.com"
        .Subject = folderName & "does not exist" & " " & Date & " " & Time
        .TextBody = folderName & "does not exist" & " " & Date & " " & Time
        .Send
    End With

    Set iMsg = Nothing
    Set iConf = Nothing

End Sub