Implement server-side spell-checking with ASP and
Hello!!!
Help me, please, I can't find mistake for a 2 days!!!
When I gonna execute code below? I got following error message:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'Documents.Add'
/Test/sch.asp, line 34
Code:
Dim objWord 'Word.Application
Dim objDocument 'Word.Document
Dim objErrors 'Word.ProofreadingErrors
Dim objError 'Word.Range
Dim wdSuggestions 'Word.SpellingSuggestions
Dim wdSuggestion 'Word.SpellingSuggestion
Dim strSubmission, strModified, intCounter
Const wdDoNotSaveChanges = 0
'On Error Resume Next 'Uncomment this line in realise version of application
'Capture submitted text from Form or QueryString
strSubmission = Request("tMess")
If Trim(strSubmission) <> "" Then
'Echo submission back to the user
With Response
.Write "<b>"
.Write "Ãåçóëüòà ò ïðîâåðêè ïðà âîïèñà Ãèÿ:</b>"
.Write "<br><br>"
.Write "<b>Ãðîâåðÿåìûé òåêñò:</b><br>"
.Write """ & strSubmission & ""<br><br>"
End With
'Launch Word and create a new document
Set objWord = Server.CreateObject("Word.Application")
If Not IsEmpty(objWord) Then
Set objDocument = objWord.Documents.Add
If Not IsEmpty(objDocument) Then
'Insert the user's submitted text into the document
objWord.Selection.TypeText CStr(strSubmission)
'Retrieve and display spelling errors
Set objErrors = objDocument.SpellingErrors
If objErrors.Count Then 'there are errors
With Response
.Write "<table><tr><td><b>Ãøèáêè ïðà âîïèñà Ãèÿ "
.Write "</b></td><td><b>ÃðåäëîæåÃèÿ ïî èñïðà âëåÃèþ</b></td></tr>"
End With
For Each objError In objErrors
'Display the misspelled word
Response.Write "<tr valign=top><td>"
Response.Write objError.Text & "</td><td>"
'Get spelling suggestions for the word
Set wdSuggestions = objWord.getSpellingSuggestions(objError.Text)
If wdSuggestions.Count < 1 Then
Response.Write "Ãåò ïðåäëîæåÃèé"
Else
intCounter = 0
For Each wdSuggestion In wdSuggestions
intCounter = intCounter + 1
strModified = Replace(strSubmission, objError.text, wdSuggestion.name, 1, 1)
With Response
'Construct anchor tag
.Write "<a href=sch.asp?"
.Write "tMess="
.Write server.URLEncode(strModified)
.Write ">" & wdSuggestion.name & "</a>"
End With
'Display a pipe-delimiter except at the end
If intCounter < wdSuggestions.Count Then
Response.Write " "
End If
Next
End If
Response.Write "</td></tr>"
Next
With Response
'Show the user number of errors found
.Write "</table>"
.Write "<br><b>" & objErrors.count
.Write " Ãà éäåÃû îøèáêè:</b>"
.Write " ÃëèêÃèòå Ãà ñîâåòå äëÿ èñïðà âëåÃèÿ."
End with
Else 'no errors were found
Response.Write "<b>Ãøèáêè ÃÃ¥ Ãà éäåÃû.</b>"
End if
'Close running instance of Word and destroy objects
objWord.Quit wdDoNotSaveChanges
Set wdSuggestions = Nothing
Set objErrors = Nothing
Set objDocument = Nothing
Set objWord = Nothing
Else
objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing
End If
End If
End If
Of course, I not so smart, most of this code snippet I taken from MSDN library and just do little error-handling here...anyway it doesn't work...and help me...
P.S. My english...really bad...I know...so, be friendly please...your Russian better...I hope.
|