How to look up text in VB.NET word
This article mainly introduces VB.NET word how to check the text, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
VB.NET word looks up the text code:
Public Class ThisDocument Private MyDocMenu As Office.CommandBarButton Private missing = System.Reflection.Missing.Value 'add menu group 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) in the ribbon Office.CommandBarPopup) If (MyCommandBarPopup IsNot Nothing) Then MyCommandBarPopup.Caption = "file management" MyDocMenu = CType (MyCommandBarPopup.Controls.Add (_ Office.MsoControlType.msoControlButton, missing, _ missing, missing, True), Office.CommandBarButton) MyDocMenu.Caption = "find text" 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 'find text 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) While (MyRange.Find.Found) MyRange.Bold = 1 MyCountMyCount = MyCount + 1 MyRange.Find.Execute (missing, _ missing, _ missing, missing) End While MessageBox.Show (MyFind + "Total found: + MyCount.ToString () +"! ", _" 51cto Information Tip ", MessageBoxButtons.OK MessageBoxIcon.Information) End Sub End Class, thank you for reading this article carefully. I hope the article "how to look up the text in VB.NET word" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!