我的想法是使用引用我使用宏来获取的列表的Attachment.Add
来附加Excel文件。宏读取文件夹中的文件并将其显示在列中。从该列我想通过Excel附加这些文件。我一直在下面的行中收到错误。
.Attachments.Add Filelist & "\" & "Attch"
有人可以帮忙吗?
Sub Sendemailusingword()
Dim Olapp As Outlook.Application
Dim Olemail As Outlook.MailItem
Dim olmail As Object
Dim olinsp As Outlook.Inspector
Dim wddoc As Word.Document
Dim count As Integer
Dim x As Integer
Dim Filelist As String
Dim Attch As String
x = 1
row_number = 7
count = Sheet1.Range("K1")
For x = 1 To count
row_number = row_number + 1
Attch = Sheet1.Range("D" & row_number).Value
Filelist = "K:\3SHARE\2016 Plan\Statment Email Send"
Set Olapp = New Outlook.Application
Set Olemail = Olapp.CreateItem(olMailItem)
With Olemail
.Display
.To = Sheet1.Range("G" & row_number)
.Subject = Sheet1.Range("D6") & Sheet1.Range("F" & row_number)
.SentOnBehalfOfName = "ComdataCommissions@comdata.com"
.BodyFormat = olFormatHTML
.CC = Sheet1.Range("H" & row_number) & ";" & Sheet1.Range("I" & row_number)
Set olinsp = .GetInspector
Set wddoc = olinsp.WordEditor
Sheet1.Activate
Range("B2").CurrentRegion.Copy
wddoc.Range.Paste
.Attachments.Add Filelist & "\" & "Attch"
End With
Next x
End Sub
答案 0 :(得分:1)
.Attachments.Add Filelist & "\" & Attch
假设变量Attch包含要附加的文件的文件名。
编辑:注意到你用 excel-vba-mac 标记,在这种情况下,我不认为反斜杠可以作为路径分隔符。 :
或/
应该有效,或使用Application.PathSeparator