有人知道如何通过word vba中的电子邮件发送word文档的链接吗?我想使用gmail而不是outlook。我找到了一个解决方案:
http://www.rondebruin.nl/win/s1/outlook/bmail10.htm
无论如何可以修改为使用gmail工作吗?
我修改了http://www.rondebruin.nl/win/s1/cdo.htm以使用gmail,它运行正常。我只需要添加一个指向电子邮件正文的链接。
答案 0 :(得分:0)
您需要使用htmlBody
属性而不是TextBody
,并在HTML中使用<a>
标记。
答案 1 :(得分:0)
我不知道如何发送我的代码......所以我发布了它作为答案。希望没关系。此外,我得到一个奇怪的运行时错误,我以前没有得到。除此之外它还有效。
谢谢! 丹尼尔
选项明确'为dSavage修改
'如果您有GMail帐户,那么您可以尝试使用此示例来使用GMail smtp服务器 '该示例将发送一条小短信 '在测试代码之前,您必须更改四个代码行
'。项目(“http://schemas.microsoft.com/cdo/configuration/sendusername”)=“完整的GMail邮件地址” '.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword”)=“GMail密码”
'使用您自己的邮件地址来测试此行中的代码 '.To =“邮件地址接收者”
'将YourName更改为您要使用的From名称 '.From =“”“你的名字”“”“
'如果出现此错误:传输无法连接到服务器 '然后尝试将SMTP端口从25更改为465
Sub CDO_Mail_Example() 昏暗的iMsg作为对象 昏暗的iConf作为对象 Dim strbody As String Dim sAddForm As String Dim sForm As String Dim Flds As Variant
Dim iSMTP_Port As Integer
Dim sFirstReviewer As String
Dim sUserName As String
Dim sGmailPassword As String
sFirstReviewer = Range("F4").Value
sUserName = Range("F6").Value & "@indicate1.com"
sGmailPassword = Range("F8").Value
iSMTP_Port = Range("F10").Value '25 at Indicate; 465 away.
sAddForm = Range("I12").Value
'sForm = Range("F4").Value
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
如果sAddForm =“是”那么 sForm =“Z:\ Quality##Document_Development#Documents_for_Review \ 12002-01-01 Company Handbook.doc” 其他 sForm =“” 结束如果
Debug.Print "sForm = " & sForm ' *******************************************
Debug.Print "sUserName = " & sUserName ' *******************************************
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sUserName
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Micro5cope"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = iSMTP_Port '25 at Indicate; 465 away.
.Update
End With
strbody = "To " & sFirstReviewer & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4" & vbNewLine & vbNewLine & vbNewLine & _
"Z:\Quality\# # Document_Development\# Documents_for_Review\12000-00-00 Tables 9-11 Template OLD - TEST.doc" & vbNewLine & _
sForm & vbNewLine
With iMsg
Set .Configuration = iConf
.To = sFirstReviewer & "@indicate1.com"
.CC = "" 'sUserName & "; " & "johanson111@comcast.net"
.BCC = ""
.From = sUserName
.Subject = "Test Message"
.textbody = strbody
.HtmlBody = "<A HREF=""http://www.google.com/"">Google Page</A>"
.AddAttachment "Z:\Quality\# # Document_Development\12001-02-01 Document Review Form.pdf"
.AddAttachment "Z:\Quality\# # Document_Development\12001-02 Document Review Draft 9.doc"
.Send
End With
Debug.Print "CC = " & sUserName ' *******************************************
End Sub