VBA +从 Word 2007 发送邮件
我在我的Word文档(office 2007)中得到了下面的代码来发送带有附件的邮件 行抛出语法错误(找不到文件)
它在.Attachement.Add "C:\abc.txt"
代码:
Private Sub CommandButton1_Click()
Dim outlookapp As Object
Dim item As Object
Dim subject As String
Dim msg As String
Set outlookapp = CreateObject("outlook.application")
msg = "Enter Message here"
subject = "Enter subject here"
Set item = outlookapp.createitem(0)
With item
.to = "[email protected] <mailto:[email protected]> "
.subject = subject
.body = msg
.Display
.Attachments.Add "C:\abc.txt"
End With
End Sub
我做错了什么?
谢谢
I got below code in my Word Document (office 2007) to send a mail with attachement
It throws syntax error (file not found) at line
.Attachement.Add "C:\abc.txt"
Code:
Private Sub CommandButton1_Click()
Dim outlookapp As Object
Dim item As Object
Dim subject As String
Dim msg As String
Set outlookapp = CreateObject("outlook.application")
msg = "Enter Message here"
subject = "Enter subject here"
Set item = outlookapp.createitem(0)
With item
.to = "[email protected] <mailto:[email protected]> "
.subject = subject
.body = msg
.Display
.Attachments.Add "C:\abc.txt"
End With
End Sub
What am I doing wrong ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
向项目添加附件的语法应将文件名括在方括号中。
尝试使用
而不是
The syntax for adding an attachment to an item should have the file name enclosed in brackets.
Try using
instead of
我尝试了上面的代码,它对我有用。您能否附加位于 C 根目录以外的位置的文件,例如 c:\docs\ ?
编辑评论
如果路径有空格,您将需要额外的引号:
I tried the code above and it worked for me. Can you attach a file located somewhere other than the root of C, for example, c:\docs\ ?
EDIT Re Comment
If the path has spaces, you will need extra quotes: