| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 其他 >> 实例分析正文
最新推荐 更多内容
VB.Net在word中查找文字
VB.Net在word中查找文字
作者:Ilu    来源:乐博网整理     更新时间:2009-9-25

乐博网lob.cn提示:调试环境为 vs2008 +  windows2003 / windows2008 / xp / vista

VB.Net在word中查找文字

Public Class ThisDocument
    Private MyDocMenu As Office.CommandBarButton
    Private missing = System.Reflection.Missing.Value
    '在功能区中新增菜单组
    Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        Dim MyCommandBarPopup As Office.CommandBarPopup = Nothing
        Dim MyCommandBarMenu As Office.CommandBar = CType( _
            Application.CommandBars.ActiveMenuBar, Office.CommandBar)
        Dim MyControlsCount As Integer = MyCommandBarMenu.Controls.Count
        MyCommandBarPopup = CType(MyCommandBarMenu.Controls.Add( _
            Office.MsoControlType.msoControlPopup, missing, missing, _
            MyControlsCount, True), Office.CommandBarPopup)
        If (MyCommandBarPopup IsNot Nothing) Then
            MyCommandBarPopup.Caption = "文件管理"
            MyDocMenu = CType(MyCommandBarPopup.Controls.Add( _
                Office.MsoControlType.msoControlButton, missing, _
                missing, missing, True), Office.CommandBarButton)
            MyDocMenu.Caption = "查找文字"
            AddHandler MyDocMenu.Click, AddressOf MyDocMenuCommand_Click
        End If
    End Sub
    Private Sub ThisDocument_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    End Sub
    '查找文字
    Private Sub MyDocMenuCommand_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
        Dim MyFind As String = ""
        Dim MyFindForm As New Form1()
        MyFindForm.ShowDialog()
        MyFind = MyFindForm.textBox1.Text
        If (MyFind.Length < 0) Then
            Return
        End If
        Dim MyCount As Integer = 0
        Dim MyDocument As Word.Document = Me.Application.ActiveDocument
        Dim MyRange As Word.Range = MyDocument.Content
        MyRange.Find.ClearFormatting()
        MyRange.Find.Forward = True
        MyRange.Find.Text = MyFind
        MyRange.Find.Execute(missing, missing, missing, missing, missing, _
                             missing, missing, missing, missing, missing, _
                             missing, missing, missing, missing, missing)
        While (MyRange.Find.Found)
            MyRange.Bold = 1
            MyCount = MyCount + 1
            MyRange.Find.Execute(missing, missing, missing, missing, _
                missing, missing, missing, missing, missing, missing, _
                missing, missing, missing, missing, missing)
        End While
        MessageBox.Show(MyFind + "一共找到:" + MyCount.ToString() + "个!", _
            "乐博网信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
End Class

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    VB.Net在word中搜索指定条件的信息
    VB.Net为word设置页眉页脚
    VB.Net为word设置封面
    VB.Net为word添加和删除注释
    VB.Net输出Word和Excel报表的实例

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]