這篇文章主要介紹了VB.NET word如何查文字,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比臺州網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式臺州網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋臺州地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。
VB.NET word查文字代碼:
Public Class ThisDocument Private MyDocMenu As Office.CommandBarButton Private missing = System.Reflection.Missing.Value '在功能區(qū)中新增菜單組 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() + "個(gè)!", _ "51cto信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub End Class
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“VB.NET word如何查文字”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!