文章編號: 243844 - 上次校閱: 2003年11月24日 - 版次: 2.0

HOWTO:從 Visual Basic 或 Visual Basic for Applications 中自動啟用 Word 的拼字檢查功能

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
本文曾發行於 CHT243844

在此頁中

全部展開 | 全部摺疊

結論

為與 Microsoft Office 搭配使用而撰寫的軟體可以利用 Microsoft Word 的拼字檢查功能,將拼字檢查功能加入自己的應用程式中。

Word 的「自動」模式包含 拼字檢查 功能,可讓您檢查 Word 中文件的拼字是否正確。使用 Word 的自動功能,開發人員可以動態地建立新文件,加入一些要檢查的文字,讓 Word 檢查拼字。本文示範如何讓 Word 自動提供此功能。

其他相關資訊

您可以從 Microsoft Visual Basic 或 Microsoft Visual Basic for Applications 使用此程式碼範例,不需經過任何變更。然而,此範例假設您是使用 Visual Basic 用戶端建立新專案。

建立拼字檢查用戶端

  1. 啟動 Visual Basic,然後建立新的 「標準 EXE」 專案。根據預設值,這會建立 Form1。
  2. 新增一個「文字方塊」(TextBox) 控制項與「指令按鈕」(CommandButton) 至 Form1。
  3. 在 Form1 的程式碼視窗中,加入下面程式碼:
    Option Explicit
    
    Private Sub Form_Load()
       Text1.Text = "This is some mispelled textt. " & _
       "We'll send it to Word and recieve the resultes."
       Command1.Caption = "Spell Check"
    End Sub
    
    Private Sub Command1_Click()
       Dim oWord As Object
       Dim oTmpDoc As Object
       Dim lOrigTop As Long
       
     ' Create a Word document object...
       Set oWord = CreateObject("Word.Application")
       Set oTmpDoc = oWord.Documents.Add
       
    ' Position Word off screen to avoid having document visible...
       lOrigTop = oWord.Top
       oWord.WindowState = 0
       oWord.Top = -3000
       
     ' Assign the text to the document and check spelling...
       With oTmpDoc
         .Content.Text = Text1.Text
         .Activate
         .CheckSpelling
       
       ' After user has made changes, get text back...
         Text1.Text = .Content.Text
       
       ' Close the document and exit Word...
         .Saved = True
         .Close
       End With
       Set oTmpDoc = Nothing
       
       oWord.Top = lOrigTop
       oWord.Quit
       Set oWord = Nothing
       
    End Sub
  4. 編譯並執行此程式。按 [Command1] 指令按鈕,執行拼字檢查功能。Word 的拼字檢查對話方塊會隨即出現以確認「mispelled」、「textt」、「recieve」與「resultes」等字的拼法是否正確。當您修正拼錯的字之後,這個文字就會傳回文字方塊。

?考

本文件是根據 Microsoft Knowledgebase 文件編號 Q243844 翻譯的。若要參考原始英文文件內容,請至以下網址:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q243844 (http://support.microsoft.com/kb/243844/en-us?ln=en-us&sd=gn&fr=0)

這篇文章中的資訊適用於:
  • Microsoft Word 2002 Standard Edition
  • Microsoft Word 2000 Standard Edition
  • Microsoft Word 97 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 4.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Office Word 2003
關鍵字:?
kbhowto kbvbp kbautomation kbvbp400 kbvbp500 kbvbp600 kbword kbvba kbgrpdso KB243844
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。