Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts

    visible issue using new ActiveXObject('Word.Application')

    I converted this to work in an hta.

    http://www.pcmag.com/article2/0,4149,460693,00.asp

    You use it by selecting the text you want to spell check then click spell.

    It works but I can't stop Word from flashing on screen when the spell check is complete. If I fill the function full of this.focus() and objWord.visible = false it minimizes the flash but it's still there. Any Ideas?

    Code:
    <html>
    <head>
    <title>Spell Check</title>
    
    <script type="text/javascript">
    
    fso = new ActiveXObject("Scripting.FileSystemObject")
    
    onload = function() {
    document.onselectstart = Who_Was_Selected
    }
    
    Selected_Element_Id = ''
    
    function Who_Was_Selected() {
    if (event.srcElement.id && document.selection.type == 'Text') {
    Selected_Element_Id = event.srcElement.id
    }
    }
    
    
    // http://www.pcmag.com/article2/0,4149,460693,00.asp
    
    function Spell_Check() {
    
    var str, objWord, CTR
    
    if (document.selection.type  == 'Text') {
    
    try {
    
    document.execCommand("Copy")
    
    str = window.clipboardData.getData("Text").replace(/^\s+/,"").replace(/\s+$/,"")
    
    CTR = document.getElementById(Selected_Element_Id).createTextRange()
    CTR.findText(str);
    CTR.select();
    
    document.execCommand("Copy")
    
    objWord = new ActiveXObject('Word.Application');
    objWord.Documents.Add();
    objWord.visible = false
    objWord.Selection.Paste();
    objWord.ActiveDocument.CheckGrammar();
    objWord.Selection.WholeStory();
    objWord.Selection.Copy();
    objWord.visible = false
    objWord.ActiveDocument.Close(0);
    objWord.Quit();
    
    document.execCommand("Paste")
    }
    
    catch(e) {
    alert(e + '\n\nThis error occurred while\nattempting to load MS Word')
    }
    
    }
    objWord = null
    }
    
    
    </script>
    </head>
    <body>
    
    <input type="button" value="Spell" onclick="Spell_Check()">
    
    <textarea id="TextArea0" rows="5" cols="20"></textarea>
    
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I thought I'd take another run at this. It's a mess but it works. WindowState was the key.

    There's atleast 1 workaround in it that probably isn't neccesary.

    I couldn't get the last example in the following link to return correctly. Instead I used focus to find if a spell/grammar correction was needed.

    http://msdn.microsoft.com/library/de.../D4/S5A94D.asp
    Code:
    <html>
    <head>
    <title>Spell Check</title>
    
    <script type="text/javascript">
    
    // fso just so spell check works 1st time (focus issue)
    fso = new ActiveXObject("Scripting.FileSystemObject")
    
    onload = function() {
    document.body.attachEvent('onselectstart', Who_Was_Selected)
    document.body.attachEvent('onfocusin', on_focus_in)
    document.body.attachEvent('onfocusout', on_focus_out)
    Input_Selected = false
    this_blur = false
    }
    
    
    function Who_Was_Selected() {
    if (document.selection.type == 'Text') {
    Selected_Element = event.srcElement
    }
    if (event.srcElement.isContentEditable) {
    Input_Selected = true
    } else {
    Input_Selected = false
    }
    }
    
    
    function on_focus_in() {
    this_blur = false
    }
    
    
    function on_focus_out() {
    this_blur = true
    }
    
    
    // http://www.pcmag.com/article2/0,4149,460693,00.asp
    
    function Spell_Check() {
    
    var str, objWord, CTR
    
    if (document.selection.type  == 'Text') {
    
    try {
    
    document.execCommand("Copy")
    
    if (Input_Selected) {
    str = window.clipboardData.getData("Text").replace(/^\s+/,"").replace(/\s+$/,"")
    CTR = document.selection.createRange()
    CTR.findText(str)
    CTR.select()
    document.execCommand("Copy")
    }
    
    objWord = new ActiveXObject("Word.Application")
    objWord.WindowState = 2
    
    objWord.Documents.Add()
    objWord.Selection.Paste()
    objWord.ActiveDocument.CheckGrammar()
    objWord.Selection.WholeStory()
    objWord.Selection.Copy()
    
    window.clipboardData.setData('text', window.clipboardData.getData("Text").replace(/^\s+/,"").replace(/\s+$/,""))
    
    if (!this_blur) {
    alert('Correct spelling and grammar')
    }
    if (Input_Selected) {
    CTR.text = window.clipboardData.getData("Text")
    }
    objWord.ActiveDocument.Close(0)
    //objWord.ActiveWindow.Close(0)   // ActiveWindow seems to work the same as ActiveDocument
    objWord.Quit()
    
    } catch(e) {
    alert(e + '\n\nThis error occurred while\nattempting to load MS Word')
    }
    objWord = null
    }
    
    }
    </script>
    </head>
    <body>
    <input type="button" value="Spell" onclick="Spell_Check()">
    <p></p>
    <textarea rows="5" cols="20">txt area</textarea>
    <p></p>
    <div ContentEditable>Content Editable</div>
    <p></p>
    Page txt
    </body>
    </html>

    <edit>
    Regular page text is just corrected and copied to the clipboard
    </edit>
    Last edited by Graeme Hackston; 05-27-2003 at 12:00 AM.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    That sounds like an interesting utility...

    can you give me a hint as to why I get the "occurred while attempting to load MS Word" error?

    (the spell-check isn't working--yet, I have that program... )

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi swmr, I'm not sure why. This is the same thing with try/catch removed. If you could, give it a try and (if you have error alerts turned on in IE) it will give you the error and line number.
    Code:
    <html>
    <head>
    <title>Spell Check</title>
    
    <script type="text/javascript">
    
    // fso just so spell check works 1st time (focus issue)
    fso = new ActiveXObject("Scripting.FileSystemObject")
    
    onload = function() {
    document.body.attachEvent('onselectstart', Who_Was_Selected)
    document.body.attachEvent('onfocusin', on_focus_in)
    document.body.attachEvent('onfocusout', on_focus_out)
    Input_Selected = false
    this_blur = false
    }
    
    
    function Who_Was_Selected() {
    if (document.selection.type == 'Text') {
    Selected_Element = event.srcElement
    }
    if (event.srcElement.isContentEditable) {
    Input_Selected = true
    } else {
    Input_Selected = false
    }
    }
    
    
    function on_focus_in() {
    this_blur = false
    }
    
    
    function on_focus_out() {
    this_blur = true
    }
    
    
    // http://www.pcmag.com/article2/0,4149,460693,00.asp
    
    function Spell_Check() {
    
    var str, objWord, CTR
    
    if (document.selection.type  == 'Text') {
    
    document.execCommand("Copy")
    
    if (Input_Selected) {
    str = window.clipboardData.getData("Text").replace(/^\s+/,"").replace(/\s+$/,"")
    CTR = document.selection.createRange()
    CTR.findText(str)
    CTR.select()
    document.execCommand("Copy")
    }
    
    objWord = new ActiveXObject("Word.Application")
    objWord.WindowState = 2
    
    objWord.Documents.Add()
    objWord.Selection.Paste()
    objWord.ActiveDocument.CheckGrammar()
    objWord.Selection.WholeStory()
    objWord.Selection.Copy()
    
    window.clipboardData.setData('text', window.clipboardData.getData("Text").replace(/^\s+/,"").replace(/\s+$/,""))
    
    if (!this_blur) {
    alert('Correct spelling and grammar')
    }
    if (Input_Selected) {
    CTR.text = window.clipboardData.getData("Text")
    }
    objWord.ActiveDocument.Close(0)
    //objWord.ActiveWindow.Close(0)   // ActiveWindow seems to work the same as ActiveDocument
    objWord.Quit()
    
    objWord = null
    }
    
    }
    </script>
    </head>
    <body>
    <input type="button" value="Spell" onclick="Spell_Check()">
    <p></p>
    <textarea rows="5" cols="20">txt area</textarea>
    <p></p>
    <div ContentEditable>Content Editable</div>
    <p></p>
    Page txt
    </body>
    </html>

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Line 59:

    objWord = new ActiveXObject("Word.Application")

    ---------------------------------------------------------
    error: Automation server can't create object
    ---------------------------------------------------------

    I've done some unproductive searching on this error:

    it is portrayed as a "security issue", but nothing seems to prevent it... I tried both using an .hta, and lowering all activeX permissions to "enable" (for the local zone), with no luck.

    Perhaps "Word.Application" isn't being recognized?
    Last edited by swmr; 05-27-2003 at 06:13 AM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try lowering your security locally.

    Also, If XP is the same as 98, hit Ctrl + Alt + Delete and see if WinWord is running. If so, close that. You might have to do it a couple times until you get the box with the "End Task" dialogue.

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well this doesn't appear to be a local security issue, because I can get THIS example to work without error...

    new ActiveXObject("InternetExplorer.Application");

    I wonder where one might find the proper name for a particular automation server on one's own system (such as the word processor)... is there a title listed in the registry, or something?

    What I mean to ask is: where is it written that the Microsoft Word Processor is identified as "Word"? How would I check this?

    There just doesn't seem to be any information about OLE scripting errors, anywhere--which really makes understanding difficult.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    the flashing of the word window was caused by the order of the statements in your code:
    first you had:
    Code:
    objWord = new ActiveXObject('Word.Application');
    objWord.Documents.Add();
    objWord.visible = false
    first load a new document, then make the window invisible, this causes the flashing

    then you had:
    Code:
    objWord = new ActiveXObject("Word.Application")
    objWord.WindowState = 2
    objWord.Documents.Add()
    first make the window invisible, then add a new document.

    for the other question: when you install office, word identifies itself as word in the system (registry) so does excel, powerpoint etc.
    Office has an architecture that every application can be invoked as an ActiveX object in every client with ActiveX capabilities. You can use the office components in a VB-app. So not every application can be treated this way, only the apps which are designed to act as an ActiveX component
    I am the luckiest man in the world

  • #9
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Aha... no Office = no toys!

    thanks for revealing that

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes thank you Roelf


  •  

    Posting Permissions

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