Page 1 of 2 12 LastLast
Results 1 to 40 of 65

Thread: Advanced VB/Office Guru™ Word SpellChecker™.NET

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Arrow Advanced VB/Office Guru™ Word SpellChecker™.NET

    Gangsta Yoda™ ®

    Description:
    I wrote this to demonstrate how to take full advantage of MS Word's built in Spelling and Grammar checker. There
    are a few other code examples that show how to do spell checking with Word but they are all using the same technique that
    seems to have a few issues like showing the spell dialog behind your app, messing up the line breaks so you need to
    apply a code fix to restore them, flashing window, etc.

    What makes my spell checker different is that I use the actual spell/grammar checking dialog window and not invoking it by
    coding the usual - "Document.CheckSpelling" which seems to cause the mentioned issues.

    Since I use the dialog window I preset the type of spelling I wish to perform. Now you can make it dynamic by having a
    spell options form in your app to allow the user to preset it to either Ignore words in UPPERCASE, urls, mixed words and
    numbers, check grammer, and whether to show spelling suggestions, etc.

    Requirements:
    Microsoft Word
    Versions 10.0 - 11.0 (2002 - 2003)

    Note: I converted my VB6 version to VB.NET 2003. The VB6 version can be located here.
















    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3. 'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
    4. '
    5. 'Distribution: You can freely use this code in your own
    6. '              applications provided that this copyright
    7. '              is left unchanged, but you may not reproduce
    8. '              or publish this code on any web site, online
    9. '              service, or distribute as source on any
    10. '              media without express permission.
    11. Imports Microsoft.Office.Interop
    12.  
    13. Public Class clsSpellMe
    14.  
    15.     Friend moApp As Word.Application
    16.     Private mbKillMe As Boolean
    17.  
    18.     Friend Property KillMe() As Boolean
    19.         Get
    20.             InitializeMe()
    21.             KillMe = mbKillMe
    22.         End Get
    23.         Set(ByVal Value As Boolean)
    24.             mbKillMe = Value
    25.         End Set
    26.     End Property
    27.  
    28.     Friend Sub InitializeMe()
    29.         Try
    30.             '<INITIALIZE WORD>
    31.             moApp = DirectCast(GetObject(, "Word.Application"), Word.Application)
    32.         Catch ex As Exception
    33.             If TypeName(moApp) = "Nothing" Then
    34.                 moApp = DirectCast(CreateObject("Word.Application"), Word.Application)
    35.                 mbKillMe = True
    36.             Else
    37.                 MessageBox.Show(ex.Message, "VB/Office Guru™ SpellChecker™.NET", _
    38.                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    39.             End If
    40.         End Try
    41.     End Sub
    42.  
    43.     Friend Function SpellMe(ByVal msSpell As String) As String
    44.  
    45.         Dim oDoc As Word.Document
    46.         Dim iWSE As Integer
    47.         Dim iWGE As Integer
    48.         Dim iResp As Integer
    49.         Dim sReplace As String
    50.  
    51.         If msSpell = String.Empty Then Exit Function
    52.         Try
    53.             InitializeMe()
    54.             Select Case moApp.Version
    55.                 Case "9.0", "10.0", "11.0"
    56.                     oDoc = moApp.Documents.Add(, , 1, True)
    57.                 Case "8.0"
    58.                     oDoc = moApp.Documents.Add
    59.                 Case Else
    60.                     MessageBox.Show("Unsupported Version of Word.", "VB/Office Guru™ SpellChecker™.NET", _
    61.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    62.                     Exit Function
    63.             End Select
    64.             oDoc.Words.First.InsertBefore(msSpell)
    65.             iWSE = oDoc.SpellingErrors.Count
    66.             iWGE = oDoc.GrammaticalErrors.Count
    67.             '<CHECK SPELLING AND GRAMMER DIALOG BOX>
    68.             If iWSE > 0 Or iWGE > 0 Then
    69.                 '<HIDE MAIN WORD WINDOW>
    70.                 moApp.Visible = False
    71.                 If (moApp.WindowState = moApp.WindowState.wdWindowStateNormal) Or _
    72.                     (moApp.WindowState = moApp.WindowState.wdWindowStateMaximize) Then
    73.                     moApp.WindowState = moApp.WindowState.wdWindowStateMinimize
    74.                 Else
    75.                     moApp.WindowState = moApp.WindowState.wdWindowStateMinimize
    76.                 End If
    77.                 '</HIDE MAIN WORD WINDOW>
    78.                 '<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
    79.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.CheckGrammarWithSpelling = True
    80.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.SuggestSpellingCorrections = True
    81.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreUppercase = True
    82.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreInternetAndFileAddresses = True
    83.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreMixedDigits = False
    84.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.ShowReadabilityStatistics = False
    85.                 '</PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>
    86.                 '<DO ACTUAL SPELL CHECKING>
    87.                 moApp.Visible = True
    88.                 moApp.Activate()
    89.                 iResp = moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Display
    90.                 '</DO ACTUAL SPELL CHECKING>
    91.                 If iResp < 0 Then
    92.                     moApp.Visible = True
    93.                     MessageBox.Show("Corrections Being Updated!", "VB/Office Guru™ SpellChecker™", _
    94.                     MessageBoxButtons.OK, MessageBoxIcon.Information)
    95.                     oDoc.Select()
    96.                     oDoc.Range.Copy()
    97.                     sReplace = DirectCast(Clipboard.GetDataObject.GetData("System.String", True), String)
    98.                     '<FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
    99.                     If (InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1) Then
    100.                         sReplace = Mid$(sReplace, 1, Len(sReplace) - 2)
    101.                     End If
    102.                     '</FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>
    103.                     SpellMe = sReplace
    104.                 ElseIf iResp = 0 Then
    105.                     MessageBox.Show("Spelling Corrections Have Been Canceled!", "VB/Office Guru™ SpellChecker™.NET", _
    106.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    107.                     SpellMe = msSpell
    108.                 End If
    109.             Else
    110.                 MessageBox.Show("No Spelling Errors Found" & Environment.NewLine & "Or No Suggestions Available!", _
    111.                 "VB/Office Guru™ SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    112.                 SpellMe = msSpell
    113.             End If
    114.             '</CHECK SPELLING AND GRAMMER DIALOG BOX>
    115.             oDoc.Close(False)
    116.             oDoc = Nothing
    117.             '<HIDE WORD IF THERE ARE NO OTHER INSTANCES>
    118.             If KillMe = True Then
    119.                 moApp.Visible = False
    120.             End If
    121.             '</HIDE WORD IF THERE ARE NO OTHER INSTANCES>
    122.         Catch ex As Exception
    123.             MessageBox.Show(ex.Message, "VB/Office Guru™ SpellChecker™.NET", _
    124.             MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    125.         End Try
    126.  
    127.     End Function
    128.  
    129. End Class
    Attached Images Attached Images      
    Last edited by RobDog888; Sep 13th, 2005 at 08:40 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    what Refrences Are used? I Have Office 2003 Installed, and I Tried Refrencing Microsoft.Office 11, Microsoft.Office 10, Office, and these Errors Still Stood the Test of Time.
    Please Submit an Example, in .NET

    (1): Namespace or type 'Interop' for the Imports 'Microsoft.Office.Interop' cannot be found.
    (2): Namespace or type 'of' for the Imports 'System.Runtime.InteropServices.of' cannot be found.
    (48): Type 'Word.Application' is not defined.
    (64): Type 'Word.Application' is not defined.
    (67): Type 'Word.Application' is not defined.
    (78): Type 'Word.Document' is not defined.
    (112): Name 'hSpelling' is not declared.
    (112): Name 'Word' is not declared.
    (113): Name 'Corrections' is not declared.
    (113): Name 'Word' is not declared.
    (114): Name 'Word' is not declared.
    (115): Name 'ndFileAddresses' is not declared.
    (115): Name 'Word' is not declared.
    (116): Name 'ts' is not declared.
    (116): Name 'Word' is not declared.
    (117): Name 'Statistics' is not declared.
    (117): Name 'Word' is not declared.
    (122): Name 'Word' is not declared.
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    You need to add a reference to Word. I would submit an example but I already have found one person trying to claim my code being copyrighted as his and published on his website just about 2 weeks ago. It was a member that I helped with this. I had to submit a claim to his forum's software provider. Needless to say, he had to take it down.

    Your errors are easy to fix. You need a reference to Word and it looks like you do not have the Primary Interop Assemblies installed for Office. Check the link in my signature on Office PIAs. This will give you the .Office.Interop.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Hmm, Well one Guy Ripped of Your Program as His, If its a Newb Then editing the AssemblyInfo might Tweak that.

    Whats the Difference between that Code you gave Him and the One submitted Here?
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    It was mostly an issue of him copy/pasting the code I have posted here and he changed the copyright to reflect his website.

    Anyways, did adding the Word reference help? And do you have the .Interop class available?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Arrow Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Latest Errors:

    (115): Name 'Statistics' is not declared.
    (110): 'CheckGrammarWit' is not a member of 'Microsoft.Office.Interop.Word.Options'.
    (110): Name 'hSpelling' is not declared.
    (111): 'SuggestSpelling' is not a member of 'Microsoft.Office.Interop.Word.Options'.
    (111): Name 'Corrections' is not declared.
    (113): 'IgnoreInternetA' is not a member of 'Microsoft.Office.Interop.Word.Options'.
    (113): Name 'ndFileAddresses' is not declared.
    (114): 'IgnoreMixedDigi' is not a member of 'Microsoft.Office.Interop.Word.Options'.
    (114): Name 'ts' is not declared.
    (115): 'ShowReadability' is not a member of 'Microsoft.Office.Interop.Word.Options'.
    Attached Images Attached Images  
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Ah, it seems that the forum software can not display the complete length of the code so it adds a space. Look at my original post.

    VB Code:
    1. ....ShowReadability  Statistics = False
    2.  
    3. 'Should be...
    4. ....ShowReadabilityStatistics = False
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    I Missed that Cause I Thought this had to do with a Reference issue which I thought You'd Know how to Fix.

    Coool, I Wont Patent/Copyright/etc this.

    Question =- When One Puts in 'Comments does it Compile in the Exe?
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Glad you like it.

    Comments in code do not get compiled into the exe.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    New Member
    Join Date
    Oct 1999
    Location
    Rome, Italy
    Posts
    10

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Hi,

    instead of:
    moApp.Dialogs(Word.WdWordDialog....

    I have to use
    moApp.Dialogs.Item(Word.WdWordDialog....

    Development environnment specs:
    MDE 2003 vers. 7.1.3088
    .NET Framework 1.1 vers. 1.1.4322
    MS Word 2002 SP3
    Win XP Pro SP2

    Best regards,
    Sergio.

  11. #11

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    I'm running the same MDE but SP1 on the framework version and SP1 on XP Pro. Also, Office 2003 but its just a shortcut as when I type the parenthesis after the Dialogs I get intellisense popup for the constants.
    VB Code:
    1. 'Original way with intellisense.
    2. moApp.Dialogs(Word.WdWordDialog...
    3.  
    4. 'Works for me too.
    5. moApp.Dialogs.Item(Word.WdWordDialog...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    New Member SpeedRacer's Avatar
    Join Date
    Feb 2006
    Location
    In a car
    Posts
    10

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    I dont see whats so hard? The code example given and everything you need. What more could you ask for?

    Great code example

  13. #13
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Mr Dog,

    I'm having problems with focus using your .Net spellchecker mate. Apart from this its working cool, really cool.

    I have around 10 user controls that use this, I am running in a terminal services / Citrix environment and the users have a TS desktop session running that they don't see, so it just looks like a seamless app to them. Anyway, I am creating an instance of Word on the first use of Spellchecker, then leaving it for subsequent calls.

    Sometimes, not always, the subsequent calls don't bring the spellcheck window to the front/focus so I get a hung app. Because the users can't see the citrix desktop, and never will, they're unable to do a Ctrl - Tab to switch apps/focus. Trying to get them to do something that simple normally would be difficult anyways.

    So, any suggestions Sir ?

    Thanks in advance, just holler if you need to see my current code / app.

    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  14. #14

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Welcome to th Forums.

    Post what your doing. It shouldnt be an issue.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Hiya RobDog, really great forum, I've added this to my list of resources. And really great work on this spellchceck class, it's fabulous! I'm playing around with it in VS2005 and all seems well in order. Learned a lot from it just about MSWord alone :-) I'm having difficulties with one thing, and that is when I set killme() to 'true', it likes to kill *all* instances of Word... even previously opened, mutually exclusive, documents. Now there's a fun trick to play on the enduser! lol. I wonder if anyone else has this issue and what they have done about it... I have a feeling I'm going to have to set the .doc to visible=false rather than the app itself, regardless, if I figure it out I'll post here.
    Last edited by RobDog888; Jun 1st, 2006 at 06:13 AM.

  16. #16

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Thanks for the props

    Sounds like the KillMe property is not finding the instance of Word already open so when it closes it kills the Word application object even though you have child documents in it.

    You should only be executing the killme if your closing your program or you dont anticipate performing any more spellchecks. If you do another then it takes time for word to start again.

    I'm off to bed right now but what version of Word are you running? Can you test it a bit more and post the findings for me tomorrow (actually today. Its 4 am). I'll take a look at it in a few.


    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    @Proggy_Dylan

    If your not going to include my copyright code comments in your program then there will be no support and I request that you remove it from your app.

    Your attachment has been archived and removed from your post.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Sure thing, can do. I'm using Office 2003 on my development machine. I did a quick build and tried to run it on a machine that has Office 2002 and ran into an entirely different snag.. stdole version needs an upgrade in the global assembly cache... I think this means I need a reference to the older office objects as it can't load the office interop for version 11 on the machie with Office 2002 (duh). I'm not in any hurry so it may take me a couple of days... sleep well... 4am eh? bit of a workaholic? lol.

  19. #19

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    lol yup

    If your creating a setup package and have the PIAs then you shouldnt have an issue but then again I havent had any other version other then 2003 so...

    Its supossed to be that when you use the PIAs you dont have to worry about versioning. You can always use late binding and remove the references to Office and Word. Then you would have to go and cast all your types correctly so you can use Option Strict still.

    Man, I got to stop posting and get some sleep. Should be up in a few hours though as I have to be up before 9am. 4.5 hours sleep should be good for a while.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Ok, Bare with me... late binding has created a load of fun for me. I can see where this is going to solve my compatibility issues, but yeesh, VS2005 likes to complain about everything. Also, since I'm not familiar with working with MSWord this way, this is a bit of a learning curve --and to do it.. option stric has to be off.. late binding is not allowed otherwise... so no intellisense... AH!

    Anyways... I've gotten this far with this challenge...

    1. when I declare the moApp and oDoc as objects, it likes to complain about all the references to word.wsWindowState (says 'word' is not delared)

    2. also complains about moApp.Dialogs(word.aWdWordDialog... (says 'word' is not declared)

    3. It doesn't like the Direct Cast statement (says 'word.application' is not defined)

    if I replace the word. with moApp., and I sub in object for word.application in the direct cast statement, it builds fine, but it throws errors on the btn_click event saying that Public member 'WdWindowState' on type 'ApplicationClass' not found.

    I'm finding I don't know enough about how to talk to Word. I think. Oi.

  21. #21

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Sorry for the delay but I had a project deadline due today.

    Did you include at the top the "Imports Microsoft.Office.Interop"?
    for some of the unrecognized "word" codes try fully qualifing it like so...

    Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMaximize

    etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    You can also do ...
    Imports Word = Microsoft.Office.Interop

    to initialize "Word" so it will be recognized when you go ...
    word.wsWindowState but shouldnt windowstate be wdWindowState and not wsWindowState.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Delay? What delay? I'm happy to be getting the suggestions Off to give it a try...

  24. #24
    New Member
    Join Date
    Jun 2006
    Posts
    6

    My Findings...

    If you develop on a machine with VS2005 and Office 2003 but you want this code to work on a PC with Office XP

    Hey again Robdog, and others... sorry for taking a long time to get back, I've been playing with the PIA's and learning the ins and outs, and how to get this code to work on an Office XP machine when compiling in a VS2005 environment with Office 2003 installed.

    I found the best way to get this to work is to simply to get the XP PIAs and reference them instead.. the idea being building from the lowest common denominator will ensure backward compatibility.

    So, for people doing what I'm doing here's an idea...

    1) download the XP PIA's available from Microsoft. http://www.microsoft.com/downloads/d...displaylang=en
    2) Extract them to some folder in your project dir (anywhere is ok, but for this example I'm saying extract to a folder named XP_PIA_COMs)
    3) In visual studio...drop the project's reference to the version 11 (Office 2003) Microsoft.Office.Interop.Word.dll
    4) Finally, Add a new reference to the OFFICE XP COM library by browsing to the XP_PIA_COMs directory chosing Microsoft.Office.Interop.Word.dll.

    Now it will build properly using Early binding, it will run on a machine with Office 2003 and will also be backwards compatible to Office XP machines.

    KEEP IN MIND, if you already develop on a machine with Office XP, you will by default have the XP (2002) PIAs, *and* you have less chance of encountering any issues.

    A note re Late Binding: I believe even if you were to do this using a late binding reference, you would still have to have the XP PIAs. Late binding is a pain in VS2005 and this is by far an easier out... in my humble opinion.

  25. #25

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Glad to see that you got it working now. Like I posted in #25, using the PIAs is a big advantage and makes life easier.

    When needing to Late bind, you should add the reference like your early binding so you can get all the intellisense. Then when finished you can remove the reference and convert to late binding.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Sweet idea! I never would have thought of that. :-)

  27. #27
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Dear Rob,
    Can we restrict the editing in the first box?
    Please mark you thread resolved using the Thread Tools as shown

  28. #28

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    How do you mean? In the Word Spell Checking Dialog?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #29
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Dear Rob,
    Is it able to disable editing in the Not in Dictionary Box?
    Please mark you thread resolved using the Thread Tools as shown

  30. #30

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    There is no built in property or support for disabling the textbox but perhaps by subclassing the dialog window and sending a disable message it will work but allot of work for a small feature. Couldnt you just check after the dialog is dismissed?
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  31. #31
    Banned ScriptKing1's Avatar
    Join Date
    May 2007
    Location
    idk
    Posts
    4

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Warning 1 Function 'SpellMe' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. 37 40 Programmers_Editor_v1
    I keep getting this warning, and I can't fix it. Also, When I run it, everything runs fine, exept for when I want to check the spelling and I press the button, it doesn't do anything. Do you know what names I should give my text box and button? Here is my code.
    vb Code:
    1. Option Explicit On
    2. Option Strict On
    3. 'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
    4. '
    5. 'Distribution: You can freely use this code in your own
    6. '              applications provided that this copyright
    7. '              is left unchanged, but you may not reproduce
    8. '              or publish this code on any web site, online
    9. '              service, or distribute as source on any
    10. '              media without express permission.
    11. Imports Microsoft.Office.Interop
    12. Public Class SpellCheck
    13.     Friend moApp As Word.Application
    14.     Private mbKillMe As Boolean
    15.     Friend Property KillMe() As Boolean
    16.         Get
    17.             InitializeMe()
    18.             KillMe = mbKillMe
    19.         End Get
    20.         Set(ByVal Value As Boolean)
    21.             mbKillMe = Value
    22.         End Set
    23.     End Property
    24.     Friend Sub InitializeMe()
    25.         Try
    26.             '<INITIALIZE WORD>            
    27.             moApp = DirectCast(GetObject(, "Word.Application"), Word.Application)
    28.         Catch ex As Exception
    29.             If TypeName(moApp) = "Nothing" Then
    30.                 moApp = DirectCast(CreateObject("Word.Application"), Word.Application)
    31.                 mbKillMe = True
    32.             Else
    33.                 MessageBox.Show(ex.Message, "VB/Office Guru™ SpellChecker™.NET", _
    34.                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    35.             End If
    36.         End Try
    37.     End Sub
    38.     Friend Function SpellMe(ByVal msSpell As String) As String
    39.         Dim oDoc As Word.Document
    40.         Dim iWSE As Integer
    41.         Dim iWGE As Integer
    42.         Dim iResp As Integer
    43.         Dim sReplace As String
    44.         If msSpell = String.Empty Then Exit Function
    45.         Try
    46.             InitializeMe()
    47.             Select Case moApp.Version
    48.                 Case "9.0", "10.0", "11.0"
    49.                     oDoc = moApp.Documents.Add(, , 1, True)
    50.                 Case "8.0"
    51.                     oDoc = moApp.Documents.Add
    52.                 Case Else
    53.                     MessageBox.Show("Unsupported Version of Word.", "VB/Office Guru™ SpellChecker™.NET", _
    54.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    55.                     Exit Function
    56.             End Select
    57.             oDoc.Words.First.InsertBefore(msSpell)
    58.             iWSE = oDoc.SpellingErrors.Count
    59.             iWGE = oDoc.GrammaticalErrors.Count
    60.             '<CHECK SPELLING AND GRAMMER DIALOG BOX>            
    61.             If iWSE > 0 Or iWGE > 0 Then
    62.                 '<HIDE MAIN WORD WINDOW>                
    63.                 moApp.Visible = False
    64.                 If (moApp.WindowState = Word.WdWindowState.wdWindowStateNormal) Or _
    65.                 (moApp.WindowState = Word.WdWindowState.wdWindowStateMaximize) Then
    66.                     moApp.WindowState = Word.WdWindowState.wdWindowStateMinimize
    67.                 Else
    68.                     moApp.WindowState = Word.WdWindowState.wdWindowStateMinimize
    69.                 End If
    70.                 '</HIDE MAIN WORD WINDOW>                
    71.                 '<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>                
    72.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.CheckGrammarWithSpelling = True
    73.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.SuggestSpellingCorrections = True
    74.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreUppercase = True
    75.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreInternetAndFileAddresses = True
    76.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreMixedDigits = False
    77.                 moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.ShowReadabilityStatistics = False
    78.                 '</PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)>                
    79.                 '<DO ACTUAL SPELL CHECKING>                
    80.                 moApp.Visible = True
    81.                 moApp.Activate()
    82.                 iResp = moApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Display
    83.                 '</DO ACTUAL SPELL CHECKING>                
    84.                 If iResp < 0 Then
    85.                     moApp.Visible = True
    86.                     MessageBox.Show("Corrections Being Updated!", "VB/Office Guru™ SpellChecker™", _
    87.                     MessageBoxButtons.OK, MessageBoxIcon.Information)
    88.                     oDoc.Select()
    89.                     oDoc.Range.Copy()
    90.                     sReplace = DirectCast(Clipboard.GetDataObject.GetData("System.String", True), String)
    91.                     '<FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>                    
    92.                     If (InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1) Then
    93.                         sReplace = Mid$(sReplace, 1, Len(sReplace) - 2)
    94.                     End If
    95.                     '</FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT>                    
    96.                     SpellMe = sReplace
    97.                 ElseIf iResp = 0 Then
    98.                     MessageBox.Show("Spelling Corrections Have Been Canceled!", "VB/Office Guru™ SpellChecker™.NET", _
    99.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    100.                     SpellMe = msSpell
    101.                 End If
    102.             Else
    103.                 MessageBox.Show("No Spelling Errors Found" & Environment.NewLine & "Or No Suggestions Available!", _
    104.                 "VB/Office Guru™ SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    105.                 SpellMe = msSpell
    106.             End If
    107.             '</CHECK SPELLING AND GRAMMER DIALOG BOX>            
    108.             oDoc.Close(False)
    109.             oDoc = Nothing
    110.             '<HIDE WORD IF THERE ARE NO OTHER INSTANCES>            
    111.             If KillMe = True Then
    112.                 moApp.Visible = False
    113.             End If
    114.             '</HIDE WORD IF THERE ARE NO OTHER INSTANCES>        
    115.         Catch ex As Exception
    116.             MessageBox.Show(ex.Message, "Welcome To Programmer's Editor Spell Check", _
    117.             MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    118.         End Try
    119.     End Function
    120. End Class
    My button is named "Command1", and the text box is "Text1"Thanks, ScriptKing1
    Last edited by ScriptKing1; May 3rd, 2007 at 04:44 PM.

  32. #32
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Hello,

    Sweet module, I have used the one that pops up Word in the past, but this one rocks!

    Anyway... I am using Office 2007 and at first it gave me an "Unsupported Office" error, but adding 12.0 to the moApp check works.

    Will that come back and bite me in the butt later or...

    tnx
    ~j

  33. #33

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    You can use Late Binding so you can support multiple version of Word.

    See my Office FAQ (link inmy signature).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  34. #34
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Question Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    thanks for the code. I'm using it in office 2003 + vb .net 2005 express. I found, sometimes, the word window will not close after the spell checker finish the work. is it normal? or, something I missed?

    I noticed that if I only do spell check, it is ok. the problem always happens when I do grammer check.

    anyone knows the reason? how to close it?


    thanks

    bear

  35. #35

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Thanks.

    Doing a grammer check only or together with a spell check?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  36. #36
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    I checked it. It doesn't matter doing grammer check only or with spell check, or spell check only. There is no WORD running at the background. When I do the check (grammer or spell) in the first time, it is always ok. WORD disappeared. But, in the background, there is a WORD process. So when you check it in the second time, if the text has error (grammer or spell), the WORD will show up and do the check, but it will not become disappear when the check finished. There is a WORD window (no doc in it) at the bottom. Sometimes, this focus will not come back to the program which calls the checker class. This WORD window gets the focus (although it is minimized).

    I think the problem is: the checker class didn't quit WORD correctly.

    I changed the code:
    [vb]
    If KillMe = True Then
    moApp.Visible = False
    End If
    [/vb]

    to

    [vb]
    Dim Ret As Boolean = KillMe ' just use the property's Get
    moApp.Visible = False
    [/vb]

    The WORD window won't show up (of course, ), but the WORD process is still there, didn't quit. And sometimes, the spell checker window shows at below the current forum although it got focus.

    I'm using winxp pro, vb express 2005 and XP_PIA_COMs (explained in #27).

    I'll check more.


    thanks

    bear



    Quote Originally Posted by RobDog888
    Thanks.

    Doing a grammer check only or together with a spell check?

  37. #37

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    Is this on 2005 or 2003? In 2005 the GetObject function is flakey at best.

    Edit: I see it is 2005. I may have to update the article for 2005
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  38. #38
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    I noticed that in debug mode, this happens 1 out of 3 times, but if I run the program in release mode, this does not happen very often, but it happens.

    Right now, what I do is:
    when spell checker is launched, I check the process, if WinWord existed, then I ask users save and quit it. Then, in program, I use
    ' ''If KillMe = True Then
    ' '' moApp.Visible = False
    ' ''End If
    Code:
                Try
                    moApp.Quit(False, Nothing, Nothing)
                Catch ex As Exception
                    gcLog.LogInfo("WORD Quit Error!")
                Finally
                    moApp = Nothing
                End Try
    instead of
    Code:
    If KillMe = True Then
        moApp.Visible = False
    End If
    This way, the spell checker dlg always gets focus and stays at the top when it is called. The cons are:
    users have to save & quit word before launch spell checker;

    But I do have a question. When the spell checker is launched in the first time, it takes some time, since it needs lauch WORD. In the program I quit WORD. SO, I think when I launch spell checker in the second (or later) time (without quiting the program which launch spell checker), it SHOULD take some time too since it will launch WORD again. However, I found in the second time, it is very fast, just like WORD is launched already although I can't see the process WinWord.

    Actually, fast is good, just feel weird. Maybe it has certain relation with the OS? I guess,

    bear

  39. #39

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    No, if its not properly disposed of it will retain it in memory which is why the second run will be fast just like other second or subsequent runs. This is only for when there is an issue quitting word.

    If you have it set so Word is destroyed each time with the KillMe = True, cause no running instance of Word was detected, then it will start up a new instance off Word and be slow. You can get over this by starting Word hidden when your app starts. Then it will just add docs and close docs as you spell check and be fast all the time. Then upon the app closing you kill that instance of Word.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  40. #40
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    362

    Re: Advanced VB/Office Guru™ Word SpellChecker™.NET

    does it mean if the PC installed office 2007, then we have to use PIA for 2007 and recompile the program? if a PC installed PIA2007, and word 2002, will it work? how about on vista? anyone knows?


    thanks

    bear

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width