vba - .vba 中的附件问题
问题描述
Dim strto As String
Dim lastrow As Long
stirfile = Dir(DestPath & "*.pdf*")
For i = lastrow To 7 Step 1
lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
strto = Range("G7") & ";" & Range("K7") & ";" & Range("O7") & ";" & Range("S7")
With Mail
.Subject = "Quote reg for VAM project"
.From = "arunkumarg@gmail.com"
.To = strto
.CC = ""
.BCC = ""
.TextBody = strbody
.Attachments.Add (DestPath)
End With
Next i
Mail.Send
End Sub
我只想将我的 destpath 中的所有 pdf 文件发送到 gmail 并且我在“.Attachment”区域失败了请指导我
解决方案
这演示了如何遍历文件夹中的文件Dir
。
Option Explicit ' Consider this mandatory
' Tools | Options | Editor tab
' Require Variable Declaration
' If desperate declare as Variant
Private Sub attachFilesInFolder()
Dim myMail As MailItem
Dim olApp As outlook.Application
Dim DestPath As String
Dim stirFilePath As String
Dim stirFile As String
DestPath = "P:\kin\PROJECTS\TARSON\Newfolder1\"
stirFilePath = DestPath & "*.pdf"
Debug.Print
Debug.Print "stirFilePath.......: " & stirFilePath
Set olApp = New outlook.Application
Set myMail = olApp.CreateItem(0)
With myMail
.Subject = "Quote reg for VAM project"
stirFile = dir(stirFilePath)
Debug.Print "DestPath & stirFile: " & DestPath & stirFile
Do While stirFile <> ""
Debug.Print " stirFile....: " & stirFile
.Attachments.add (DestPath & stirFile)
stirFile = dir
Loop
End With
myMail.Display
End Sub