C# Visual Studio 2010中VBA到C的转换

C# Visual Studio 2010中VBA到C的转换,c#,visual-studio-2010,vba,outlook,vsto,C#,Visual Studio 2010,Vba,Outlook,Vsto,我正在将VisualStudio2010与VSTO一起使用。目前,我正在通过一个功能区按钮修改邮件正文的内容 我知道wordeditor是outook2007中的默认编辑器。那么,在使用word editor for inspector窗口(撰写邮件窗口)时,如何获取正文文本以执行搜索和替换操作呢 我在VBA中有一个宏代码,它工作得非常好。我想将这段代码转换成C sharp,当在“撰写邮件”窗口中单击功能区按钮时,该代码将起作用 Sub ASAtoHyperlinkCompose() Dim

我正在将VisualStudio2010与VSTO一起使用。目前,我正在通过一个功能区按钮修改邮件正文的内容

我知道wordeditor是outook2007中的默认编辑器。那么,在使用word editor for inspector窗口(撰写邮件窗口)时,如何获取正文文本以执行搜索和替换操作呢

我在VBA中有一个宏代码,它工作得非常好。我想将这段代码转换成C sharp,当在“撰写邮件”窗口中单击功能区按钮时,该代码将起作用

Sub ASAtoHyperlinkCompose()

 Dim uiInspector As Outlook.Inspector

 Dim uiObject  As Object

 Dim uiItem   As Outlook.MailItem

 Dim uiDoc   As Word.Document

 Set uiInspector = Application.ActiveInspector

 Set uiObject = uiInspector.CurrentItem

 If uiObject.MessageClass = "IPM.Note" And _

  uiInspector.IsWordMail = True Then

  Set uiItem = uiInspector.CurrentItem

  Set uiDoc = uiInspector.WordEditor

  With uiDoc.Range.Find

   .Text = "ASA^$^$^#^#^#^#^#"

   While .Execute

   .Parent.Hyperlinks.Add .Parent, _

  "http://stack.com=" & .Parent.Text & "outlook2007"

    .Parent.Collapse wdCollapseEnd

   Wend

  End With

  End If

End Sub

我不熟悉Outlook的自动化和工具箱。这与转换为C#的代码大致相同。如果没有别的,那就是一个开始。供参考的报表中没有C#等价物

private void ASAtoHyperlinkCompose()
   {                                           
       var uiInspector = Application.ActiveInspector;

       var uiObject = uiInspector.CurrentItem;

       if (uiObject.MessageClass.ToString().Equals("IPM.Note") && uiInspector.IsWordMail)
       {
           var uiItem = uiInspector.CurrentItem;

           var uiDoc = uiInspector.WordEditor;

           uiDoc.Range.Find.Text = "ASA^$^$^#^#^#^#^#";

           while (uiDoc.Range.Find.Execute())
           {
               uiDoc.Range.Find.Parent.Hyperlinks.Add(uiDoc.Range.Find.Parent, string.Format(@"http://stack.com={0}outlook2007", uiDoc.Range.Find.Parent.Text));
               uiDoc.Range.Find.Parent.Collapse(wdCollapseEnd);

           }
       }
   }