在VBA脚本中,我正在尝试编写一个具有以下签名的子函数
Sub(taskName As String , myGroup As String, myFile As String ,myPer As String, RelatedTasks() As String )
Dim olApp As Outlook.Application
Dim m As Outlook.MailItem
Set olApp = New Outlook.Application
Set m = olApp.CreateItem(olMailItem)
With m
.display
.To = "somewhere@someplace.com"
.Subject = "Test Events"
.HTMLBody/.body = ...
End Sub
电子邮件正文如下:
大家好,
请查看以下信息。
任务:taskName
相关任务:RelatedTasks()
文件:myFile
PERSON :myPer
在Sub函数中,冒号左侧的模式始终是常量。右侧将根据函数的输入而改变。
为此,我正在阅读包含所需签名的Template.htm。
Template.htm包含:
Hello All,
Please find the following information.
TASK: {{mytask}}
RELATED TASK:{{myRelatedTasks}}
FILE : {{myFile}}
PERSON : {{myPerson}}
在VBA代码中,我正在替换所有字段。
我面临的问题是{{mytask}}和{{related tasks}}也应该有HTML参考。我已经成功添加了mytask的链接。点击邮件中的mytask将跳转到相应的网络链接。
<a href = "www.something.com&id ={{taskID}}>
{{mytask}}.....<a href = "www.xxx.com&id={{}}>{{myRelatedTasks}}
但是在将相同的任务添加到相关任务时遇到了麻烦,因为它是一个数组。
我的VBA代码:
Option Explicit
Sub CreateNewMail()
Dim olApp As Outlook.Application
Dim m As Outlook.MailItem
Dim sigPath As String, sigText As String
Dim fso As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim t As String
Dim r(5) As Variant
t = "233444:dshfjhdjfdhjfhjdhfjdhfjd"
r(0) = "122343:dsjdhfjhfjdh"
r(1) = "323243:jfjfghfjhjddj"
r(2) = "834783:gffghjkjkgjkj"
Set olApp = New Outlook.Application
Set m = olApp.CreateItem(olMailItem)
sigPath = "C:\Users\Pavan-Kumar\Desktop\vbs\TestEvents.htm"
Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile(sigPath)
sigText = ts.ReadAll
ts.Close
Set fso = Nothing
sigText = Replace(sigText, "{{mytask}}", t)
sigText = Replace(sigText, "{{myRelatedTasks}}", Join(r, "<br>"))
With m
.display
.To = "somewhere@someplace.com"
.Subject = "Test Events"
.HTMLBody = sigText
End With
End Sub
而且,当我加入相关任务时,我希望他们在缩进时来到另一个下面。我试着给它&#34; \ t&#34;作为分隔符没有成功。
我目前在Outlook邮件中的O / P:
答案 0 :(得分:0)
以下是我为解决同一问题所做的工作:
{{recipient name}}
Replace
填写您的字段。例如strHTMLTemplate = Replace(strHTMLTemplate, "{{recipient name}}", "Jane Doe")
对于RelatedTasks,看起来你只想让它们在一行上。在这种情况下,只需创建一个&#34;字段&#34;在您的模板{{RelatedTasks}}
中,然后像strHTMLTemplate = Replace(strHTMLTemplate, "{{RelatedTasks}}", Join(RelatedTasks, ", "))
那样进行替换。
如果您想获得幻想,可以编写将字符串数组转换为html Office add-ins或lists
的函数