這篇文章主要介紹了VB調用Word拼寫檢查功能,非常實用的功能,需要的朋友可以參考下
衆所周知,Word有自帶的拼寫檢查功能。VB中想要實現調用 Word 拼寫檢查功能其實很簡單就可以實現,方法是先建立word對象,然後把需要檢查的字符串放到 WORD中,調用word拼寫檢查,再取出返回值,最後關閉對象。
各個步驟的具體實現代碼如下所示:
Function CheckSpell(IncorrectText as string) as string Dim Word As Object, retText$ On Error Resume Next '建立WORD對象並打開 Set Word = CreateObject("Word.Basic") '把需要檢查的 STRING 放到 WORD Word.AppShow Word.FileNew Word.Insert IncorrectText '調用WORD 拼寫檢查 Word.ToolsSpelling Word.EditSelectAll '得到返回值 retText = Word.Selection$() CheckSpell = Left$(retText, Len(retText) - 1) '關閉文件 Word.FileClose 2 Show Set Word = Nothing End Function
本實例備有詳細的註釋,幫助讀者理解,此外讀者還可以在本實例的基礎上參閱其他資料做進一步的改善,以實現更爲強大的功能!