Page 1 of 1

ShellExecute

Posted: Wed Dec 09, 2009 2:07 pm
by driessen
Hello,

I want to open a Word document without using OLE.
But I also want a macro to be executed.

Normally for opening a document and executing a macro MACRO you do :
WINWORD.EXE LETTER.DOC /MMACRO
Because I don't know the exact path of WINWORD.EXE, I want to use ShellExecute()

So I tried this code :

Code: Select all

ShellExecute(,"Open","LETTER.DOC","/MMACRO",,3)
The document is opened in Word, but the macro MACRO is not executed, although the 4th position is ment to add parameters.

What can I do to execute the macro in an automatic way ?

Thanks a lot in advance for any help.

Re: ShellExecute

Posted: Wed Dec 09, 2009 6:25 pm
by Jack
Michel,

Try with winexec .

lnf:="i:\Ret"+dtos(date())+substr(time(),1,2)+"h"+substr(time(),4,2)+".doc"
WinExec( "winword " + lnf )

Good luck .

Ph Jacquet (Belgium)

Re: ShellExecute

Posted: Wed Dec 09, 2009 9:43 pm
by Antonio Linares
Michel,

Have you tried with "//MMACRO" ? (notice the two //)

Re: ShellExecute

Posted: Thu Dec 10, 2009 10:25 am
by driessen
Antonio,

You are the greatest. The double backslash was the right solution.

(After EDIT : Sorry, the problem is not solved - see my new message)

Thank you very much.

To Philippe,

I also tried your WINEXEC proposal, but it doesn't work.

But thank you for your effort.

Re: ShellExecute

Posted: Thu Dec 10, 2009 10:28 am
by anserkk
Hi,
Can anybody explain, What is the difference between ShellExecute() and WinExec(). Is there any performance difference between the two ?

Regards
Anser

Re: ShellExecute

Posted: Thu Dec 10, 2009 10:47 am
by driessen
Sorry, Antonio, the problem was not solved.

the double backslash doesn't seem to be a solution.

Anyone any idea ?

Thanks.

Re: ShellExecute

Posted: Thu Dec 10, 2009 11:04 am
by Patrizio
Driessen, http://msdn.microsoft.com/en-us/library ... S.85).aspx
lpParameters
[in] If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
So, you can't pass parameter if you open a .doc.

But, if you open a exe you can, try this

Code: Select all

shellexecute(,"open","winword.exe","LETTER.DOC /MMACRO")

Re: ShellExecute - now it is solved

Posted: Thu Dec 10, 2009 4:58 pm
by driessen
Patrizio,

Thank you very much for your help.

Your suggestion is working fine. My problem is solved.

Thank you, guys.