Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ole failure with Word
Message
 
 
To
12/12/2001 06:36:49
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00593151
Message ID:
00594395
Views:
25
>Have a look at this code snipet, why then would we get the following error on some machines
>
>Error:
>"Ole Error" Ole idispatch exception code from Microsoft Word the open method or property is not available because the current selection is not in the main document Window"
>
>What causes this, I suspect its not the code but HW related.
>
>oWord=CREATEOBJECT("word.Application")
>IF TYPE('oWord') = 'O'
> oWord.visible=.t.
> oWord.Windowstate = 2
> oWord.documents.Open ("c:\temp\infile")
> oWord.Windowstate = 1
> oWord.WordBasic.FileSaveAs ("c:\temp\outfile", 0)
>ENDIF

I've run into similar problems. Could this user have another instance of Word open? Could they have manipulated the Word environment? Word honors exactly what's open at the time; it doesn't have any knowledge that you're executing a program and that all those commands belong together. It's just processing what it gets. Here's a way to code that explicitly states what you want done, and to which object:
IF TYPE('oWord') = 'O'
    oWord.visible=.t.
    oWord.Windowstate = 2
    oDocument = oWord.documents.Open("c:\temp\infile")
    oWord.Windowstate = 1
    oDocument.SaveAs(c:\temp\outfile")
ENDIF
By having an object reference (oDocument), it specifies to Word exactly which document you want to work on, so it can eliminate ambiguity that leads to errors that have to do with documents not being in the active window.

Here's another tip: in new code, don't use WordBasic. It was the only way to Automate Word'95, but with the object model overhaul in '97, it was relegated to "backwards compatibility" status (meaning no new updates, and it may disappear from the next release of Word).

- della
Previous
Reply
Map
View

Click here to load this message in the networking platform