您好,登錄后才能下訂單哦!
這篇文章主要介紹了VB.NET word如何查文字,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
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 MyCountMyCount = 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() + "個!", _ "51cto信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub End Class
感謝你能夠認真閱讀完這篇文章,希望小編分享的“VB.NET word如何查文字”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。