VB icon

MsSpellCheck( string ) : string

Email
Submitted on: 1/1/2015 2:03:00 PM
By: Eric Russell (from psc cd)  
Level: Not Given
User Rating: By 3 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 1335
 
     This short and sweet function accepts a string containing text to be spell checked, checks the text for spelling using MS Word automation, and then returns the processed text as a string. The familiar MS Word spelling dialog will allow the user to perform actions such as selecting from suggested spellings, ignore, adding the word to a customized dictionary, etc.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: MsSpellCheck( string ) : string
' Description:This short and sweet function accepts a string containing text to be
spell checked, checks the text for spelling using MS Word automation,
and then returns the processed text as a string. The familiar
MS Word spelling dialog will allow the user to perform actions such
as selecting from suggested spellings, ignore, adding the word to a
customized dictionary, etc.
' By: Eric Russell (from psc cd)
'
' Inputs:String - Text to be checked for spelling
'
' Returns:String - Text after modification by user from the Word spell checking dialog.
'
' Assumes:You need to have Microsoft Word95 or higher installed on the PC. Just place the function in a project module or the general declaration section of a form.
'
' Side Effects:There are no known side effects.
'**************************************

' Description: This function accepts a string containing text to be
' spell checked, checks the text for spelling using MS Word automation,
' and then returns the processed text as a string. The familiar
' MS Word spelling dialog will allow the user to perform actions such
' as selecting from suggested spellings, ignore, adding the word to a
' customized dictionary, etc.
'Syntax: MsSpellCheck( String ) : String
'Author: Eric Russell
'E-Mail: erussell@cris.com
' WEB Site: http://cris.com/~erussell/VisualBasic
' Created: 1998-13-14
' Revised: 1998-04-03
'Compatibility: VB 5.0, VB 4.0(32bit)
' Assumptions: The user must have MS Word95 or higher installed on
'their PC.
'References: Visual Basic For Applications, Visual Basic runtime
'objects and procedures, Visual Basic objects and procedures.
'
Function MsSpellCheck(strText As String) As String
Dim oWord As Object
Dim strSelection As String
Set oWord = CreateObject("Word.Basic")
oWord.AppMinimize
MsSpellCheck = strText
oWord.FileNewDefault
oWord.EditSelectAll
oWord.EditCut
oWord.Insert strText
oWord.StartOfDocument
On Error Resume Next
oWord.ToolsSpelling
On Error GoTo 0
oWord.EditSelectAll
strSelection = oWord.Selection$
If Mid(strSelection, Len(strSelection), 1) = Chr(13) Then
 strSelection = Mid(strSelection, 1, Len(strSelection) - 1)
End If
If Len(strSelection) > 1 Then
 MsSpellCheck = strSelection
End If
oWord.FileCloseAll 2
oWord.AppClose
Set oWord = Nothing
End Function


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.