c# - MS Word 中的语法高亮显示

标签 c# ms-word ms-office

是否可以为 MS Word 创建一个插件或加载项,允许选择一段文本,然后对其应用自定义“突出显示”功能。

我希望这一切都在 MS Word 中,而不是来自另一个应用程序的剪切和过去。

如果可能的话,关于我在哪里可以找到如何做到这一点的方向的任何建议(使用 C#)

最佳答案

VBA - Visual Basic for Applications 是您在 Office 中进行此类工作的工具。它也保持独立。

显示操作文本。

http://computerprogramming.suite101.com/article.cfm/introduction_to_vba_for_ms_word

VBA 教程:

http://jy.fridaynight.co.il/pages/dev/WordVBA.php

一堆例子。

http://www.thezcorp.com/VBACodeSamples.aspx

聚宝盆:

http://www.java2s.com/Code/VBA-Excel-Access-Word/CatalogVBA-Excel-Access-Word.htm

既然您也知道要搜索什么,希望您已经上路了。

编辑:找到这个代码示例:

Sub ChangeColor
    Options.DefaultHighlightColorIndex = wdBrightGreen
    Selection.Find.ClearFormatting
    Selection.Find.Highlight = True
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorBrightGreen
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorRed
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

HTH

关于c# - MS Word 中的语法高亮显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3441923/

相关文章:

VBA字: Remove SHIFT-ENTER lines

excel - 如何通过excel vba在word doc的新页面上添加文本

PDF转换服务

c# - 为什么 Interlocked.Exchange 不支持 Boolean 类型?

c# - 使用 devDept Eyeshot 查找两个 3D 形状之间的差异

c# - 从 .NET 中的数据库图像列将多个文件附加到电子邮件

c# - 如何知道在构建中使用哪个 cpu(x86 x64 或 AnyCpu)?

linux - 将 Office 文件转换为 swf (Flash)

c# - 为多个应用程序创建 VSTO 插件

excel - 如何覆盖网站安全证书以消除错误?