Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shellexecute to open a Word.doc - no reaction 1

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I would like to open a word.doc in my VFP application and have therefore constructed:
Code:
DECLARE INTEGER SellExecute in Shell32.dll ;
INTEGER hhdWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

lcFileName = "myWord.DOC"
= shellexecute(0,"open",lcFilename,"","",1)
And nothing, virtualy nothing, happens.
So I replaced lcFilename with
Code:
SYS(5)+SYS(2003)+"\archief\myWord.doc"
still nothing

needless to say.
- Word is installed on this PC
- Directory archief is found in my path
- File myWord.DOC resides in SYS(5)+SYS(2003)+"\archief"

What possibilities do I have to correct this unwanted behavior?

Regards,

Jockey(2)
 
You have a typo in your declaration.

"SellExecute"
and then you issue:
=shellexecute


Add a "h" to your declaration "ShellExecute" and it should work fine.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
On a more general point, it's always worth checking the value returned by ShellExecute(). If the value is less than or equal to 32, it is an error code. The most common error is 2, which means the file is not found.

So instead of:

Code:
= shellexecute(0,"open",lcFilename,"","",1)

you could do:

Code:
lnReply = shellexecute(0,"open",lcFilename,"","",1) 
IF lnReply = 2
  MESSAGEBOX("Cannot find " + lcFilename)
ENDIF

Keep in mind that ShellExectue does not know anything about VFP's default directory or search path, so you always need to give the document an explicit path.

For more information about the possible error codes, see Introducing ShellExecute() (the section headed 'Did it work?").

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
That's a great point Mike!


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks,

Hmm the typo was in the posting, the code was correct.
Now added lnReply and it shows error 31.
Must investigate what that means.

Jockey(2)
 
Hi,
Error 31 should mean: "There is no application associated with the given file-name extension." Which is strange since when I click on any .doc file it opens word.
What should I do to correct this and how can I be assure the users will not get the same result?
Jockey(2)
 
ShellExecute() returning Error 31 means "There is no application associated with the given file-name extension." This usually means that Word isn't properly installed. Try to double click a .doc file and see what happens.
 
Or it could mean that Word is installed, but for some reason the "doc" extension is not registered. As Tore says, double-clicking on a .doc file should tell you one way or the other.

And, of course, you should also check that lcFileName (in your example) does contain what you think it does.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Tore,

When I dblclick on any .doc file it opens msword.
When I dblclick on this particular .doc file it opens msword.

Jockey(2)
 
To follow Mike's advice, add _cliptext = lcFileName. Then Press Windows+R followed by ctrl-v and Enter. See what happens.
 
Tore,
sorry, 20 minutes later, Office repaired, still when I activate my code to run a word.doc nothing, nothing but errorcode 31.
Do we have an other solution at hand to open and show a Word document?
Regards,
Jockey(2)
 
Hi,

I found a solution/workaround.
Converted myDocument.doc into a myDocument.pdf Changed the coding accordingly and have a pdf on my screen. Disadvantage: a word.doc used to popup (2 sec) a .PDF takes around 15 secs.

So if still anybody has an other procedure to show a Word.doc than shellexecute, I am interested to use.

Thanks,

Jockey(2)
 
So, you only want to show the document - not allow the user to edit it?

You could advise the user to install quikview.exe, which does just that. But I suspect you might have the same problem.

There are a couple of other ways of opening a Word document: (i) Use Automation to invoke a Word object; (ii) drop an OLE Container control on a form.

But, if I were you, I would much prefer to try to solve the original problem rather than find a workaround.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

I agree absolutely with you, the shellexecute() should work for my word.doc. If I only know how to fix the error and know where to look for it. meanwhile a 20 (!) minute word repair was done without succes.

Thanks for moral support

Jockey(2)
 
Jockey2,
I suggest, try this:

Create a new procedure called SHELLEXEC as follows:

Code:
PROCEDURE SHELLEXEC

LPARAMETER lcLink, lcAction, lcParms
*
lcAction = IIF(EMPTY(lcAction), "Open", lcAction)
lcParms = IIF(EMPTY(lcParms), "", lcParms)
*
DECLARE INTEGER ShellExecute ;
    IN SHELL32.dll ;
    INTEGER nWinHandle, ;
    STRING cOperation, ;
    STRING cFileName, ;
    STRING cParameters, ;
    STRING cDirectory, ;
    INTEGER nShowWindow
*
DECLARE INTEGER FindWindow ;
   IN WIN32API ;
   STRING cNull,STRING cWinName
*
RETURN ShellExecute(FindWindow(0, _SCREEN.caption), ;
                    lcAction, lcLink, ;
                    lcParms, SYS(2023), 1)

Use the following to call your Word Doc (or your .PDF or whatever): (I usually put this in the double-click event so a double click launches the file):

Code:
lcLaunchFile = '"'+SYS(5)+SYS(2003)+ALLTRIM(DOCUMENT.DOCUMENTPATH)+'"' && DOCUMENT.DOCUMENT path assumes a field, but can just as easily be lcMyFile, M.FILENAME, etc, just ensure full file name+extension
*
SHELLEXEC(lcLaunchFile)

See if that works.
Your comment about PDF, I just launched a 500 page PDF with this command and procedure, which is 95MB in size, and it took less than 1 second...


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top