RobDog ... will this work with Office 2007? Some of our users are SOMETIMES getting this error:
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
Do you know how I can fix this? Thanks...
Printable View
RobDog ... will this work with Office 2007? Some of our users are SOMETIMES getting this error:
Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
Do you know how I can fix this? Thanks...
I added the 12.0 version to the Select Case and am not experiencing any issues using it.
to activate this :
1 what is needed to be installed/dl ?
2 what dll is to be referenced ?
how do i pass a string spell check it and get a : corrected string or 3 top correction strings options
(walkthrough) ?
It is all available as posted but...
1. Make a reference to Microsoft xx.x Object library.
2. Create a Windows project.
3. Add a text box
4. Add a command button.
5. Create the class.
Form logic:
ClassCode:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As New clsSpellMe
TextBox1.Text = x.SpellMe(TextBox1.Text)
End Sub
Code:Option Explicit On
Option Strict On
'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
'
'Distribution: You can freely use this code in your own
' applications provided that this copyright
' is left unchanged, but you may not reproduce
' or publish this code on any web site, online
' service, or distribute as source on any
' media without express permission.
'From http://www.vbforums.com/showthread.php?t=359879
Imports Microsoft.Office.Interop
Public Class clsSpellMe
Friend moApp As Word.Application
Private mbKillMe As Boolean
Friend Property KillMe() As Boolean
Get
InitializeMe()
KillMe = mbKillMe
End Get
Set(ByVal Value As Boolean)
mbKillMe = Value
End Set
End Property
Friend Sub InitializeMe()
Try
'<INITIALIZE WORD>
moApp = DirectCast(GetObject(, "Word.Application"), Word.Application)
Catch ex As Exception
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Word.Application"), Word.Application)
mbKillMe = True
Else
MessageBox.Show(ex.Message, "VB/Office Guru™ SpellChecker™.NET", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
End Sub
Friend Function SpellMe(ByVal msSpell As String) As String
Dim oDoc As Word.Document
Dim iWSE As Integer
Dim iWGE As Integer
Dim iResp As Integer
Dim sReplace As String
If msSpell = String.Empty Then
SpellMe = ""
Exit Function
End If
Try
InitializeMe()
Select Case moApp.Version
Case "9.0", "10.0", "11.0", "12.0"
oDoc = moApp.Documents.Add(, , 1, True)
Case "8.0"
oDoc = moApp.Documents.Add
Case Else
MessageBox.Show("Unsupported Version of Word.", "VB/Office Guru™ SpellChecker™.NET", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SpellMe = ""
Exit Function
End Select
oDoc.Words.First.InsertBefore(msSpell)
iWSE = oDoc.SpellingErrors.Count
iWGE = oDoc.GrammaticalErrors.Count
'<CHECK SPELLING AND GRAMMER DIALOG BOX>
If iWSE > 0 Or iWGE > 0 Then
'<HIDE MAIN WORD WINDOW>
moApp.Visible = False
If (moApp.WindowState = moApp.WindowState.wdWindowStateNormal) Or _
(moApp.WindowState = moApp.WindowState.wdWindowStateMaximize) Then
moApp.WindowState = moApp.WindowState.wdWindowStateMinimize
Else
moApp.WindowState = moApp.WindowState.wdWindowStateMinimize
End If
'</HIDE MAIN WORD WINDOW>
'<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.CheckGrammarWithSpelling = True
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.SuggestSpellingCorrections = True
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreUppercase = True
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreInternetAndFileAddresses = True
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreMixedDigits = False
moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.ShowReadabilityStatistics = False
'</PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
'<DO ACTUAL SPELL CHECKING>
moApp.Visible = True
moApp.Activate()
iResp = moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Display
'</DO ACTUAL SPELL CHECKING>
If iResp < 0 Then
moApp.Visible = True
MessageBox.Show("Corrections Being Updated!", "VB/Office Guru™ SpellChecker™", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
oDoc.Select()
oDoc.Range.Copy()
sReplace = DirectCast(Clipboard.GetDataObject.GetData("System.String", True), String)
'<FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
If (InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1) Then
sReplace = Mid$(sReplace, 1, Len(sReplace) - 2)
End If
'</FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
SpellMe = sReplace
ElseIf iResp = 0 Then
MessageBox.Show("Spelling Corrections Have Been Canceled!", "VB/Office Guru™ SpellChecker™.NET", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SpellMe = msSpell
End If
Else
MessageBox.Show("No Spelling Errors Found" & Environment.NewLine & "Or No Suggestions Available!", _
"VB/Office Guru™ SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SpellMe = msSpell
End If
'</CHECK SPELLING AND GRAMMER DIALOG BOX>
oDoc.Close(False)
oDoc = Nothing
'<HIDE WORD IF THERE ARE NO OTHER INSTANCES>
If KillMe = True Then
moApp.Visible = False
End If
'</HIDE WORD IF THERE ARE NO OTHER INSTANCES>
Catch ex As Exception
MessageBox.Show(ex.Message, "VB/Office Guru™ SpellChecker™.NET", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function
End Class
I have a textbox on a continuous form with a memo field control source. On double click, the text box will open another form that has it's contents displayed in a larger view, with the option to spell check, modify the text in the field and then update and close, transferring the modified text back to the original textbox control.
I want to be able to run the grammar checker in word on this expanded form as well.
Any ideas? Any .mdbs already ready already?
P.S. Unfortunately, my office still uses ACCESS 2003 and will continue to do so for an indefinite amount of time...
:wave:
Just preset in code what options you want before invoking the spelling dialog. Its shown in my first post. See line 78: '<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
It is amazing that so many have figured out how to use this although there isn't one mention anywhere as to how to call this class to start auto-checking text fields on a form. So, how is this accomplished?
Because checking fields on a form is simply just passing the fields in a loop to the SpellMe function after you instantiate the clsSpellMe class. My initial example is just for one big "field" if you will. Its up to you how you want to call or utilize it for your own needs.
Hallo, not sure if this is still supported, I love the class but cannot get it to work for me. i added version 12.0 to my moApp.Versions.
Im using office 2007
I get the following error
TheAdd method or property is not available because the document is a rich text edit control..
hope I can get this going, its exactly what im looking for.
thanks