谁能帮我编辑下面的脚本,以添加多个文件列在电子表格的第3列(列C)?
我当前的宏一次查找一个文件,并发送单独的电子邮件。我需要它来查找C列(第三列)中列出的多个文件名(在列出的文件夹路径中),并且它会这样做,直到它到达空单元格。
我当前的脚本在下面,你会看到它一次查找一个文件。
Sub AttachandSendEmail()
Dim obMail As Outlook.MailItem
Dim irow As Integer
Dim dpath As String
Dim pfile As String
'file path
dpath = "C:\Users\filelocation"
'looping through all the files and sending an mail
irow = 1
Do While Cells(irow, 3) <> Empty
'pikcing up file name from column C
pfile = Dir(dpath & "\*" & Cells(irow, 3) & "*")
'checking for file exist in a folder and if its a pdf file
If pfile <> "" And Right(pfile, 3) = "pdf" Then
Set obMail = Outlook.CreateItem(olMailItem)
With obMail
.To = "email@comapny.com"
.Subject = "O/S Blanace"
.BodyFormat = olFormatPlain
.Body = "Please see attached files"
.Attachments.Add (dpath & "\" & pfile)
.Send
End With
End If
'go to next file listed on the C column
irow = irow + 1
Loop
End Sub
发布于 2018-02-08 14:04:44
试一试,它会发送一条附加了所有文件的消息。
Set obMail = Outlook.CreateItem(olMailItem)
With obMail
.To = "email@comapny.com"
.Subject = "O/S Blanace"
.BodyFormat = olFormatPlain
.Body = "Please see attached files"
Do While Cells(irow, 3) <> Empty
'pikcing up file name from column C
pfile = Dir(dpath & "\*" & Cells(irow, 3) & "*")
'checking for file exist in a folder and if its a pdf file
If pfile <> "" And Right(pfile, 3) = "pdf" Then
.Attachments.Add (dpath & "\" & pfile)
End If
'go to next file listed on the C column
irow = irow + 1
Loop
.Send
End With
https://stackoverflow.com/questions/48678566
复制相似问题