编辑:添加了更接近实际字符串的片段,我试图操纵帖子的底部。它不是逐字逐句,删除了关键信息,但我复制并粘贴了我试图转发的电子邮件。只是试图在中间和前方提取表格。
我想删除我收到的电子邮件中的特定文字,删除超链接,保留格式,然后转发到特定地址。
基本上,电子邮件的结构如下:
"亲爱的用户,
请在下面找到相关信息
数据库:记录 点击此处在线查看
- 表格标题
- 列标题
- 记录1
- 记录2
- 记录3
- ...
- 最终记录
如果您在使用上述链接时遇到问题,请将此链接粘贴到地址栏中以转到在线数据库:
somewebsite.database.net/tr/vuioahdf
这是一封自动发送的电子邮件......"
我需要删除表格前的文本,删除超链接,保留格式并转发。
我尝试了以下内容。
Sub RemoveExpression()
Dim Insp As Inspector
Dim obj As Object
Set Insp = Application.ActiveInspector
Set obj = Insp.CurrentItem
obj.Body = Replace(obj.Body, "Dear user, please find the relevant information below database: records click here to view this online - Table header " & _
vbNewLine & "If you have trouble using the link above, paste this link in your address bar to go to the online database http://somewhere.database.net/tr/vuioahdf This is an automated email...", "")
Set obj = Nothing
Set Insp = Nothing
End Sub
它给我一个关于不定义对象的错误,但这是我想要做的事情。删除表之前和之后的一些文本,删除超链接,然后转发到特定地址。删除超链接可能不是完全必要的,因为它主要位于表格之前和之后的文本中,但表格标题中有一个超链接。
电子邮件我试图操纵:
Dear User,<br>
<br>
Please find below drawing received last week for project
<br> <br>
<b><u></u>Document Control: Projects<u></u></b><br>
Click <a href="somehwere.net" target="_blank">here</a> to see this report on the database.
<br> <br>
<div style="font-size:70%;font-family:Verdana,Helvetica,Geneva,sans-serif">
<div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#c4defb">
<td style="border-top:1px solid #55a0ef;border-bottom:1px solid #55a0ef">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="width:200px;padding:4px 8px;font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;color:#505050;font-weight:normal;font-size:9pt">
<a style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;color:#505050;font-weight:normal;font-size:9pt;text-decoration:none" href="somewhere.net" title="See this report" target="_blank">Full Report</a>
| <a style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;color:#505050;font-weight:normal;font-size:9pt;text-decoration:none" href="somewhere.net" title="Edit all the Drawings shown below" target="_blank">Grid Edit</a>
</td>
<td style="width:200px;padding:4px 8px;font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;color:#505050;font-weight:normal;font-size:9pt" align="right">
<span><label>Date Created</label> is during <label> 'last 2 wk' </label> AND ...</span> <span>11 Drawings</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<thead style="display:table-header-group">
<tr>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"> </td>
<td align="right" style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><div></div><span>Date Created</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Project Name</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Sub Project</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Project Description</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Drawing Number</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Revision</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Title</span><span></span></td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;background-color:#f6f9fd;padding:3px 4px;font-weight:bold;font-size:10pt;color:#111111"><span>Transmittal</span><span></span></td>
</tr>
</thead>
<tbody style="display:table-row-group">
<tr>
<td nowrap style="border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111"> </td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111" align="right">02-18-2016</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Rig xxx</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">120</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Structure</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">00813-121-000-001WM</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">0</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">REAR FRAME</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">02182016</td>
</tr>
<tr style="background-color:#f2f2f2">
<td nowrap style="border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111"> </td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111" align="right">02-18-2016</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Rig xxx</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">120</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Structure</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">00813-121-000-000</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">0</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">REAR ASSEMBLY</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">01282016</td>
</tr>
<tr>
<td nowrap style="border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111"> </td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111" align="right">02-18-2016</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Rig xxx</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">120</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">Structure</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">00813-121-000-001</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">0</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">REAR FRAME</td>
<td style="font-family:Helvetica Neue,Helvetica,Tahoma,Arial,sans-serif;border-left:1px solid #ccc;border-bottom:1px solid #ccc;padding:3px 4px;font-size:10pt;color:#111111">01282016</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
</div>
<br>
If you have trouble using the link above, copy and paste the following Web address into the address bar of your browser:
<br> <a href="somewhere.net" target="_blank">somewhere.net</a>
<br> <br>
This is an automated email from an online application. If you feel that you received this email in error, please contact the application's manager,
<a href="mailto:someone@projects.net" target="_blank">someone@projects.net</a>
</td></tr></table>
</div>
</font></div></table></table></div></div></body></html>
&#13;
答案 0 :(得分:1)
您收到的Body
的{{1}}属性是只读的。这可能是您收到错误的原因。您需要转发邮件,获取转发的邮件,然后对其进行操作MailItem
。
如果您收到的电子邮件中包含一大堆内容,并且您只想转发该表,则可以使用此类代码
Body
它找到表在Public Sub ForwardTableOnly()
Dim olMail As MailItem
Dim lTblStart As Long, lTblEnd As Long
Set olMail = ActiveInspector.currentItem.Forward
lTblStart = InStr(1, olMail.HTMLBody, "<table")
lTblEnd = InStr(lTblStart, olMail.HTMLBody, "</table")
olMail.HTMLBody = Mid$(olMail.HTMLBody, lTblStart, lTblEnd - lTblStart + 1)
olMail.Display
End Sub
属性中的位置并删除其他所有内容。这是有效的,但它比那更复杂。如果你想保留表格以及其他一些东西,你将会有更复杂的字符串操作。如果格式对您很重要,那么您还会遇到其他问题。表格可能是使用HTMLBody
中进一步定义的样式以及其他一些样式进行格式化的。这甚至更多的字符串操作。但是字符串操作很容易,如果不是乏味和乏味的话。
相关要点是:调用Forward方法并将生成的MailItem分配给对象变量。然后将该对象的HTMLBody
属性设置为您想要的任何属性。在此示例中,我使用HTMLBody
属性来显示消息。您可能希望使用.Display
和.To
,而不是.Send
。