用特定的超链接替换正文中的特定ID [英] Replace specific ids in body with specific hyperlinks

查看:225
本文介绍了用特定的超链接替换正文中的特定ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我完成作业后,我发布了这个问题。请帮我解决这个问题..

After my thorough homework, I am posting this question. Please help me solve this..

我想在文本正文中搜索ASA1234yy并将其替换为嵌入式超链接[ASA1234yy] [1]
在这个体内可以有很多这种类型的id,每个超链接应该是唯一的,遵循一种模式

I want to search for ASA1234yy in the body of a text and replace it with the embedded hyperlink [ASA1234yy][1] There can be many ids of this type in the body and each of theri hyperlinks should be unique which follows a pattern

到目前为止完成的代码

Sub ConvertToHyperlink(MyMail As MailItem)
Dim strID As String
Dim Body As String
Dim objMail As Outlook.MailItem
Dim temp As String
Dim RegExpReplace As String
Dim RegX As Object
strID = MyMail.EntryID

Set objMail = Application.Session.GetItemFromID(strID)
Body = objMail.Body
Body = Body + "Test"
objMail.Body = Body

Set RegX = CreateObject("VBScript.RegExp")
With RegX
.Pattern = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
.Global = True
.IgnoreCase = Not MatchCase
End With
RegExpReplace = RegX.Replace(Body, "http://www.code.com/ABCD")

Set RegX = Nothing
objMail.Body = RegExpReplace
objMail.Save
Set objMail = Nothing
End Sub

此代码仅替换整个id。如何将ID添加到超链接。
并在添加之后,我需要一个嵌入式超链接。

This code replaces the entire id only. How do I add the id to the hyperlink. and after adding it, I need a embedded hyperlink.

谢谢

好的,我的修改后的想法如下...

Ok my modified idea below...

嗨..

我是在下面描述的过程中面临两个问题..

I am facing two problems in the process described below..

将从Outlook mailitem中提取的指定文本转换为word文档中的超链接,并将其保存在outlook mailitem中。

Convert specified text extracted from Outlook mailitem to hyperlinks in word document and save it in outlook mailitem.

收到的电子邮件 - >将其保存在Word文档中 - >将文本更改为超链接 - >将已更改的WORD文档保存到Outlook邮件项


  1. 我的代码只找到文档中的第一个出现的文本,并用超链接替换它并留下其他的出现次数

  1. My code finds only the first occuring text in the document , and replaces it with a hyperlink and leaves the other ocurrences

在Word文档中进行修改后,我想将文档的内容复制到outlook mailitem。

After making modifications in the word document, I want to copy the contents of the document to the outlook mailitem.

格式化如果电子邮件有桌子和其他东西就迷路了。

Formatting getting lost if email has tables and other stuff.

我的代码在这里为你...

My code here for you...

Sub IncomingHyperlink(MyMail As MailItem)
  Dim strID As String
  Dim Body As String
  Dim objMail As Outlook.MailItem
  Dim temp As String
  Dim RegExpReplace As String
  Dim RegX As Object
  Dim myObject As Object
  Dim myDoc As Word.Document
  Dim mySelection As Word.Selection

  strID = MyMail.EntryID
  Set objMail = Application.Session.GetItemFromID(strID)

  Set objWord = CreateObject("Word.Application")
  objWord.Visible = True

  Set objDoc = objWord.Documents.Add()
  Set objSelection = objWord.Selection
  objSelection.TypeText "GOOD" & objMail.Body

  With objSelection.Find
    .ClearFormatting
    .Text = "ASA[a-z][a-z][0-9][0-9][0-9][0-9][0-9]"
    .Forward = True
    .Wrap = wdFindAsk
    .MatchWildcards = True
  End With
  'Find next instance of Pattern "ASA[a-z][a-z][0-9][0-9][0-9][0-9]"
  objSelection.Find.Execute

  'Replace it with a hyperlink
  objSelection.Hyperlinks.Add Anchor:=objSelection.Range, _
  Address:="http://www.code.com/" & objSelection.Text, _
  TextToDisplay:=objSelection.Text

  objDoc.SaveAs ("C:\Desktop\testdoc.doc")
  objWord.Quit

  objMail.Body = objSelection.Paste
  objMail.Save
  Set objMail = Nothing
End Sub

你能帮忙解决这两个问题吗?

Can you please help solve these two problems?

推荐答案

建议:只需使用Word的内置查找方法。

Suggestion: just use Word's built-in Find method.

'Set up search
With Selection.Find
    .ClearFormatting
    .Text = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
    .Forward = True
    .Wrap = wdFindAsk
    .MatchWildcards = True
End With

' Find next instance of Pattern "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
Selection.Find.Execute

' Replace it with a hyperlink
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
    Address:="http://www.code.com/" & Selection.Text, _
    TextToDisplay:=Selection.Text

以上将保留orinigal文字例如ASA5534yy并插入超链接 http://www.code.com/ASA5534yy (根据需要调整)。

The above will keep the orinigal text e.g. "ASA5534yy" and insert the hyperlink http://www.code.com/ASA5534yy (adjust as you see fit).

这篇关于用特定的超链接替换正文中的特定ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆