excel宏 - 读取文件夹中的文件名

时间:2016-08-05 13:20:38

标签: excel macros directory filenames

我正在尝试通过宏发送文件夹中的文件,但Dir()没有读取文件。

enter image description here

enter image description here

代码是:

Dim objMail As Outlook.MailItem
Dim fldName As String
Dim sName As String
Dim email As String


fldName = FolderName
i = 0

sName = Dir(fldName)
MsgBox Len(fldName)
MsgBox Len(sName)

Do While Len(sName) > 0

    Set objMail = Application.CreateItem(olMailItem)

    With objMail
        .To = email
        .BodyFormat = olFormatPlain
        .Attachments.Add (fldName & sName)
        .Display ' .send
    End With

    sName = Dir
    i = i + 1

Loop

我甚至尝试过:

fldName = Chr(34) & FolderName & Chr(34)

但它没有帮助。

enter image description here

有什么想法吗?

0 个答案:

没有答案