Page 1 of 1
Opening a Word Document (Solved)
Posted: Tue Feb 23, 2010 10:00 am
by anserkk
Dear All,
I am trying to open a Word file. Unfortunately it is throwing error. I can't understand what is wrong. I am using Vista Business and have MS Office 2007 installed in my PC. I tried this in other PC's too, but same result. Word application object is getting created, further oWordApp:Documents:Open(Filename) is giving error. I tried different word files so as to ensure that there is nothing wrong with the word file which I am trying to open
Code used
Code: Select all
#include "FiveWin.ch"
*-------------------------------------*
Function Main()
*-------------------------------------*
Local oWordApp,oWordDoc,oError
TRY
oWordApp := CreateObject("Word.Application")
CATCH
MsgInfo("MS-Word is not installed in your PC")
Return NIL
END
// Works fine till here and the next line throws an error
//Open a word file, the file Federal.doc exists in the App exe folder
// The error shown is 'Item' is not a property
TRY
oWordDoc:=oWordApp:Documents:Open("Federal.doc")
CATCH oError
MsgInfo("Error. Unable to Open the File"+CRLF+oError:Description)
oWordApp:Quit()
Return NIL
END
I have found that many of our FiveWin forum members are using the above code without any problems.
Any hint ?
Regards
Anser
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 10:06 am
by Colin Haig
Anser
Have you tried using the full path when opening the word document.
Cheers
Colin
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 10:09 am
by demont frank
Anserkk
Code: Select all
oWordDoc:=oWordApp:Documents:Open("Federal.doc")
Maybe you could try with includint the path ?
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 10:20 am
by driessen
Hello Anser,
I use this code :
Code: Select all
cWord := TOleAuto():New("Word.Application")
cWord:Documents:Open("FEDERAL.DOC")
cWord:Quit()
You also can use :
cWord:Visible := .T. (for making Word visible)
cWord:Visible := .F. (for making Word invisible)
cWord:Run("Macro") (for using a macro defined in Word)
I use this for many years and it all works very fine here.
Good luck.
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 10:53 am
by anserkk
Colin Haig wrote:Anser
Have you tried using the full path when opening the word document.
Colin
Hi Mr.Colin,
I tried, unfortunately the same error
demont frank wrote:Anserkk
Code: Select all
oWordDoc:=oWordApp:Documents:Open("Federal.doc")
Maybe you could try with includint the path ?
Mr.Demont Frank,
I tried both with and without path.
Mr.Michel,
I tried your code, but I am getting the same error
Code: Select all
cWord := TOleAuto():New("Word.Application")
cWord:Documents:Open("FEDERAL.DOC") // Here the same error ie 'Item' is not a property
cWord:Quit()
driessen wrote:I use this for many years and it all works very fine here.
I have searched web for many VB6 code and I cannot find anything wrong in the code which I have posted above and the code suggestions made by you friends. I have tried this on different PC's. Tried on Windows 7 with Ms-Office 2007, Windows XP with Ms-Office 2003, unfortunately the same result.
As the above code is working fine with all of you, I understand that nothing wrong with the code used, it should be something wrong with the kind of installations made, Antivirus....
but the same error on other PC's on my network ?
Thanks to all.
Regards
Anser
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 11:17 am
by driessen
Anser,
Can you tell us something more about the exact error ? Do you get a message ? If so, what is the message ?
Indeed, I don't see anything what might be wrong to the code you put in your topic.
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 11:36 am
by gkuhnert
Anser,
in my code I found following statement:
Code: Select all
oWord:Documents:Add("document.doc")
Maybe this helps?
Re: Opening a Word Document
Posted: Tue Feb 23, 2010 12:09 pm
by anserkk
Dear Mr.Gilbert Kuhnert ,
Thanks for the suggestion.
Dear All,
Solved the problem. It was my mistake. The problem was definitely due to the path problem. I rested for a while and then re-checked again and solved the issue. Sorry for wasting all of yours time.
Lesson learned :
Even if the Word file exists in the same folder as the App exe, the Full path of the word file is to be specified along with the Open command. It doesn't make any difference whether the Word File name extension (.doc OR .docx) is included or not.
oWordDoc:=oWordApp:Documents:Open("D:\Fwh Tests\Federal)
Even if I remove the Drive letter from the Path it is failing. I still wonder, how it works for others without a full path
Mr.Colin & Mr.Demont Frank gave a hint regarding the Full path.
Before posting the topic here I tried the full path along with the word file name, unfortunately due to minor problem with my Prg Editor installation here, the compiler was not generating the exe and I kept on testing and giving feedback based on the old exe. Only later I discovered about it
The Error description "Item is not a property" was misleading, at least to me.
Once again thanks to all.
Regards
Anser
Re: Opening a Word Document (Solved)
Posted: Tue Feb 23, 2010 2:21 pm
by Otto
Mr. Anser,
Do you have or had different word versions on your PC.
I had a similar problem. The environmental (registry) setup pointed to another word version as my current one.
Best regards,
Otto
Re: Opening a Word Document (Solved)
Posted: Tue Feb 23, 2010 3:11 pm
by driessen
Otto,
I have a solution to solve the problem with several Word versions.
You have to change the register by using regedit.exe (after having made a backup of your register, just to be sure if anything goes wrong).
Go to this key :
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options
Doubleclick on the key "NoReReg" and set the value to 0 (zero).
You have to repeat that for all Word-versions by changing the highlighted version number.
8.0 = Word 1997
9.0 = Word 2000
10.0 = Word 2002 (or XP)
11.0 = Word 2003
12.0 = Word 2007
14.0 = Word 2010
After having done that, just close the registor editor.
Then you start the Word-version which you want to be the standard (you'll probably will see a install screen for a while) and quit this Word-version again.
The start REGEDIT.EXE again and put all the "NoReReg" keys to value 1, just like we did before while giving them the value 0.
When all this is done, any Word will work when you doubleclick on its icon. But if you doubleclick on a Word-document, or start Word from you FWH-application, the Word-version which you made standard, will be launched.
I hope I could make myself clear.
Good luck.
Re: Opening a Word Document (Solved)
Posted: Wed Feb 24, 2010 5:07 am
by anserkk
Dear Mr.Otto,
Mr.Otto wrote:Do you have or had different word versions on your PC.
I had a similar problem. The environmental (registry) setup pointed to another word version as my current one.
No, I don't have multiple versions of Ms-Office installed on the same PC.
My problem was purely due to the Path problem while trying to open the Word file. You need to specify the full path including the Drive letter.
Regards
Anser
Re: Opening a Word Document (Solved)
Posted: Thu Nov 11, 2010 6:09 am
by zlatan24
For me exist two softwares for solving other problems. One of them was downloaded some days ago and assisted me to solve my old troubles. Above it the tool can help in any situation in my opinion -
word file repair tools.