简体   繁体   English

如何在 Excel VBA 中使用邮件发送多个超链接,具体取决于单元格值

[英]How to send multiple hyperlinks with mail in Excel VBA, depending on the cell value

There is and light order managment system where you can order a few items.有一个简单的订单管理系统,您可以在其中订购一些物品。 When you have chosen your order, you click a button, and the rows that is order and number of items is copied to a new confirmation sheet.选择订单后,单击一个按钮,订单和项目数量的行将复制到新的确认表中。 This sheet is then supposed to be sent to a chosen reciever by oMail.然后应该将此表通过 oMail 发送给选定的收件人。 This works fine.这工作正常。 But in one of the columns there is a certificate on PDF(hyperlink), that is linked to a server(local file on my computer:)) I'm trying to send this PDF's as multiple hyperlinks in the mail, but that is no sucess:p.但是在其中一列中,有一个关于 PDF(超链接)的证书,它链接到服务器(我计算机上的本地文件:))我正在尝试将此 PDF 作为邮件中的多个超链接发送,但那不是成功:p。 The thing I want to do is check if the cell is empty, if not, attach the hyperlink(s) in my stringbody.我要做的是检查单元格是否为空,如果不是,请在我的字符串正文中附加超链接。 And send the mail.并发送邮件。

Here is my code:这是我的代码:

在此处输入图像描述

I use a function also to make the range to html format:我还使用 function 将范围设为 html 格式:

在此处输入图像描述

It's more useful to edit e-mail body via GetInstector通过 GetInstector 编辑电子邮件正文更有用

For example:例如:

Dim myInspector As Object'inspector object
Dim wdDoc As Object''document
Dim myitem As Object'mailitem
   
   
Set myitem = CreateObject("Outlook.Application").CreateItem(0)'creating mailitem from Excel
Set myInspector = myitem.GetInspector'set inspector to edit mailitem
Set wdDoc = myInspector.WordEditor'set MS Word to edit mailbody
 
With myitem'here you are setting the e-mail properties

     .To = Email'fill to e-mail
     .Subject = Subja'Subject
     .Display'display mailitem etc.
    
End With
'here edit the body with MS Word methods
wdDoc.Range.Paragraphs.Add
wdDoc.Range.Paragraphs.item(1).Range.Text = "Something you want in 1st paragraph" & vbCr
wdDoc.Range.Paragraphs.Add
wdDoc.Range.Paragraphs.item(2).Range.Text = "Something else you want in 2nd paragraph " & vbCr

So, actually you edit e-mail programmatically the same as you do it in Word.因此,实际上您以编程方式编辑电子邮件与在 Word 中编辑电子邮件的方式相同。 It makes useless long and complicated string with HTML-tags.它使带有 HTML 标记的冗长而复杂的字符串变得无用。 You add MS Word objects and forms.添加 MS Word 对象和 forms。

I see that this is a simpler way to making the body.我看到这是制作身体的一种更简单的方法。 And thank you very much for the answer.非常感谢您的回答。 But the thing I actually need help to sort out is how I can attach my link to the PDF into the mail.但我真正需要帮助解决的问题是如何将我的 PDF 链接附加到邮件中。 I have made the StringBody, and just want to attach the links bellow the text now.我已经制作了 StringBody,现在只想在文本下方附加链接。 Thats what im trying to do with this For structure, checking how many links there are in sheet.这就是我试图用这个 For 结构做的事情,检查工作表中有多少链接。 And then get one line for each link.然后为每个链接获取一行。

enter image description here在此处输入图像描述

My excel document looks like this:我的 excel 文档如下所示:

enter image description here在此处输入图像描述

The blue ring is the hyperlink i want to add to my email body.蓝色环是我想添加到我的 email 正文的超链接。

Steinar施泰纳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM