Visual Studio 2010 中的 VBA 到 C# 转换
我正在使用带有 VSTO 的 Visual Studio 2010。目前,我正在努力在输入电子邮件后通过功能区按钮修改正文的内容。
我知道Word编辑器是Outook 2007中的默认编辑器。那么,在检查器窗口(撰写邮件窗口)中使用Word编辑器时,如何获取正文文本以执行搜索和替换操作?
我有一个 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
I am using Visual Studio 2010 with VSTO. Presently, I am working on modifying the contents of the body through a ribbon button, after the email has been typed.
I am aware the Word Editor is the default editor in Outook 2007. So how can I get the text of the body to perform search and replace operations when using word editor for the inspector window(compose mail window)?
I have a macro code in VBA, which works perfectly fine. I want to convert this code into C sharp which will work when the ribbon button is clicked in compose mail window.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉 Outlook 的自动化和工具包。这或多或少与转换为 C# 的代码相同。如果不出意外的话,这就是一个开始。没有与 C# 等效的 With 语句(仅供参考)。
I'm not familiar with Outlook's automation and toolkit. This is more or less the same code converted to C#. If nothing else it is a start. There is no C# equivalent With statement FYI.