眾所周知,Word有自帶的拼寫檢查功能。VB中想要實現(xiàn)調(diào)用 Word 拼寫檢查功能其實很簡單就可以實現(xiàn),方法是先建立word對象,然后把需要檢查的字符串放到 WORD中,調(diào)用word拼寫檢查,再取出返回值,最后關(guān)閉對象。
各個步驟的具體實現(xiàn)代碼如下所示:
Function CheckSpell(IncorrectText as string) as stringDim Word As Object, retText$ On Error Resume Next '建立WORD對象并打開Set Word = CreateObject("Word.Basic")'把需要檢查的 STRING 放到 WORDWord.AppShowWord.FileNewWord.Insert IncorrectText'調(diào)用WORD 拼寫檢查 Word.ToolsSpellingWord.EditSelectAll'得到返回值 retText = Word.Selection$()CheckSpell = Left$(retText, Len(retText) - 1)'關(guān)閉文件Word.FileClose 2 ShowSet Word = NothingEnd Function本實例備有詳細的注釋,幫助讀者理解,此外讀者還可以在本實例的基礎(chǔ)上參閱其他資料做進一步的改善,以實現(xiàn)更為強大的功能!
新聞熱點
疑難解答
圖片精選