《忽略标点符号、匹配前缀和后缀、清除突出显示》由会员分享,可在线阅读,更多相关《忽略标点符号、匹配前缀和后缀、清除突出显示(3页珍藏版)》请在金锄头文库上搜索。
1、 e800,国内最具活力的IT门户网站。http:/【e800编译】此示例演示Microsoft Word 2010中Find对象的一些功能,诸如忽略标点符号,忽略空格,匹配前缀和后缀,以及清除突出显示效果。此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。Microso
2、ft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。实例代码以下是在Word 2007中Find对象的一些新的功能:- IgnorePunct- IgnoreSpace- MatchPrefix- MatchSuffix- ClearHitHighlight- HitHighlight在一个新文档键入以下文本,然后按Enter键:= rand(5,5)这会在当前文档中插入各包含5个句子的5个段落。然后在VBA
3、编辑器中,复制这段代码到ThisDocument类中。按F8单步执行代码。并列放置VBA和Word窗口,这样你就可以查看单步代码的动作。Sub DemoFind() Set up a search, in the random text, for tab MostDim fnd As FindSet fnd = Content.Findfnd.Text = tab Most Ignore punctuation and white space. In the document, the text appears as tab. Most. This will still find a matc
4、h.fnd.IgnorePunct = Truefnd.IgnoreSpace = True Highlight the found text.fnd.HitHighlight fnd.Text, vbYellow, vbRed Now clear the highlighting. This is only meaningful if you are single-stepping through the code.fnd.ClearHitHighlight Match the text th only when it appears at the beginning of a word:f
5、nd.MatchPrefix = Truefnd.Text = thfnd.HitHighlight fnd.Text, vbYellow, vbRed Now clear the highlighting. This is only meaningful if you are single-stepping through the code.fnd.ClearHitHighlight Match the text th only when it appears at the end of a word:fnd.MatchPrefix = Falsefnd.MatchSuffix = Truefnd.Text = thfnd.HitHighlight fnd.Text, vbYellow, vbRed Now clear the highlighting. This is only meaningful if you are single-stepping through the code.fnd.ClearHitHighlightEnd Sub