Opening a Word Document (Solved)

Post Reply
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Opening a Word Document (Solved)

Post 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
Last edited by anserkk on Tue Feb 23, 2010 12:22 pm, edited 1 time in total.
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Opening a Word Document

Post by Colin Haig »

Anser

Have you tried using the full path when opening the word document.

Cheers

Colin
demont frank
Posts: 167
Joined: Thu Mar 22, 2007 11:24 am

Re: Opening a Word Document

Post by demont frank »

Anserkk

Code: Select all

oWordDoc:=oWordApp:Documents:Open("Federal.doc")
 
Maybe you could try with includint the path ?
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Opening a Word Document

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Opening a Word Document

Post 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.... :roll: but the same error on other PC's on my network ? :evil:

Thanks to all.

Regards
Anser
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Opening a Word Document

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Re: Opening a Word Document

Post by gkuhnert »

Anser,
in my code I found following statement:

Code: Select all

oWord:Documents:Add("document.doc")
Maybe this helps?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Opening a Word Document

Post 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 : :D

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 :oops:

The Error description "Item is not a property" was misleading, at least to me.

Once again thanks to all.

Regards
Anser
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Opening a Word Document (Solved)

Post 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
Last edited by Otto on Tue Feb 23, 2010 6:45 pm, edited 1 time in total.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Opening a Word Document (Solved)

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Opening a Word Document (Solved)

Post 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
zlatan24
Posts: 5
Joined: Thu Jul 02, 2009 6:46 am

Re: Opening a Word Document (Solved)

Post 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.
Post Reply