Visual Basic宏不记录MS Word 2007中的字体选择

时间:2016-06-27 11:21:05

标签: vba unicode fonts ms-word macros

我正在编辑一些使用非Unicode字体以科普特语言编写的文本文件。我正在将文件转换为Unicode。

我正在编辑的文件使用3种字体来表示发音方言。 我想创建一个宏来搜索并用Unicode替换非Unicode字符。

但是,我希望能够限制搜索并替换为某些字体。 我尝试用普通的宏来做,但宏没有记录我执行的字体选择。

除了方言标记之外,最终结果将是用Unicode字符替换其中一种字体(内置于字符中的方言标记)中的字符。

有没有办法修改下面的代码来制作MS Word注册表,我想限制搜索和替换函数到用特定字体写的字符?

   static void Main(string[] args)
    {
        string startDate = "24 June 2016 8:20:00 AM";
        string endDate   = "24 June 2016 10:00:00 AM";

        string startPKey = convertDateToPKey(startDate);
        string endPKey   = convertDateToPKey(endDate);
        Debug.WriteLine("(PartitionKey gt '" + startPKey + "'"
            + " and PartitionKey le '" + endPKey +"')"
            + " and (EventId eq 4096)"
            );
    }

    private static string convertDateToPKey(string myDate)
    {
        System.DateTime dt = System.Convert.ToDateTime(myDate);
        long dt2ticks = dt.Ticks;
        string ticks = System.Convert.ToString(dt2ticks);
        return "0" + ticks;
    }

Image showing where to choose the font

Image showing the end result

1 个答案:

答案 0 :(得分:0)

解决方案:

    Sub twoo()
'
' twoo Macro
'
'
With Selection.Find
 .Text = "n"

 ' Clear all previously set formatting for Find dialog box.
 .ClearFormatting
 ' Set font to Find for replacement.
 .Font.Name = "EXISTING FONT NAME"


 ' Clear all previously set formatting for Replace dialog box.
 .Replacement.ClearFormatting
 ' Set font to Replace found font.
 .Replacement.Font.Name = "NEW FONT NAME"

 .Replacement.Text = ChrW(11419) & ChrW(769)
 .Forward = True
 .Wrap = wdFindContinue
 .Format = True
 .MatchCase = False
 .MatchWholeWord = False
 .MatchKashida = False
 .MatchDiacritics = False
 .MatchAlefHamza = False
 .MatchControl = False
 .MatchWildcards = False
 .MatchSoundsLike = False
 .MatchAllWordForms = False
 End With
 Selection.Find.Execute Replace:=wdReplaceAll

End Sub