在MS Word的书签中插入突出显示的句子? [英] Insert highlighted sentence at bookmark in MS Word?

查看:78
本文介绍了在MS Word的书签中插入突出显示的句子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个用户窗体,用于在某些书签中用文本填充模板.为了易于查看已插入的文本,我希望将其用黄色突出显示.有没有一种便捷的方法可以对插入的每个文本执行此操作,而无需键入,选择并突出显示它?举例来说,这就是我代码的一部分,就像atm一样:

So I have a userform that I use to populate a template with text at certain bookmarks. To make it easy to see what text has been inserted, I would like it to be highlighted with yellow. Is there a convenient way to do this for every text that is inserted without typing it, selecting it and then highlighting it? As an example, this is what part of my code looks like atm:

With ActiveDocument
   Options.DefaultHighlightColorIndex = wdYellow
   '[highlight=yellow].Bookmarks("Modtager").Range.Text = TxtModtager.Value[/highlight]
  .Bookmarks("Modtager").Range.Text = TxtModtager.Value
  .Bookmarks("KSnr1").Range.Text = txtKSnr.Value
  .Bookmarks("KSnr2").Range.Text = txtKSnr.Value

第一行似乎无能为力-即使没有打开该选项,新文本仍不会突出显示.

The first line doesn't seem to do anything - even without the option turned on new text is still not highlighted.

第二行是我在另一个站点上找到的东西,但由于无法正常工作而不得不对其进行评论.

The second line is something I found at another site but had to be commented as it's not working.

最后三行插入实际文本,我想您可以选择先选择书签,然后选择Selection.TypeText Text:=我需要什么值",然后再次选择新短语(如何?)并选择.HighlightColorIndex = wdYellow.

The last three lines insert the actual text and I guess you could choose to select the bookmark first and then Selection.TypeText Text:="Whatever value I need", followed by selecting the new phrase again (how?) and choose .HighlightColorIndex = wdYellow.

应该有更好的方法,有什么建议吗?:)

There should be a better way though, any suggestions? :)

推荐答案

这对我有用:

SetBkmkText "Modtager", TxtModtager.Value
SetBkmkText "KSnr1", txtKSnr.Value
SetBkmkText "KSnr2", txtKSnr.Value


Sub SetBkmkText(bkmk as String, NewText as String)
    With ActiveDocument.Bookmarks(bkmk).Range
        .Text = NewText 
        .HighlightColorIndex = wdYellow
    End With
End Sub

这篇关于在MS Word的书签中插入突出显示的句子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆