PDA

Click to See Complete Forum and Search --> : ShellExecute


uiligheid
Feb 8th, 2001, 08:42 AM
Hi,

I am building a little program that will be started from either Excell or Word. I already got a general idea how I can let my program know if Excell or Word is running.

I am using this code:

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long


StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"i am word", "C:\", SW_SHOWNORMAL)



Excell and Word have this code in their macro. But.... I do not know how I can let my program see the line "I am Word". I already tried calling a msgbox with lpszParams in it, but it didn't work.

Any suggestions ?

jonaxse
Feb 8th, 2001, 10:21 AM
I am confused with what you are doing. If you are automating word or excel, then you may be doing VBA right?

If so, Msgbox is an internal VBA function that will popup a small window with a text on it, and an Icon.

Syntax: Msgbox <text>, <type of buttons> + <type of icons>, <title>

Please don`t get annoyed, Im just confused with what you are doing.

And if you want ta` run an external program from VBA in word or excell, then the Shell Function can get handy.

Syntax: Shell <program path and filename>, <execution type>

Example: Shell "c:\command.com", vbNormalFocus

---NOTE: This function executes asynchronously, therefore program control returns as soon as "c:\command.com" is started.

uiligheid
Feb 9th, 2001, 02:01 AM
I can see your confusion, I'm sorry.

The program I build has to be executed from my macros. But, when word and excel are running, the program that is being called has to know which one called.

So , the shell command will not suffice, because i can't give my .exe a variable.


Shell ("C:\program.exe")


That's all a shell can do, but I need to give it a signal like "he! I am word!"

Hope I'm clearer now.

jonaxse
Feb 9th, 2001, 02:18 AM
This should be pretty straight-forward.

Ever wondered if its possible to execute your program like this: myprgram.exe /m hello!

Well, its possible!! Surprise!! :)

It all has to do with the Command Function

Here is a sample:


=================================
'this is your program
Sub Main()
Dim sParam As String

sParam = Command()
Msgbox sParam
End Sub
=================================
NOTE: In this case I tried to get the parameters at the start-up of the program.

Function Info:
"...For applications developed with Visual Basic and compiled to an .exe file, Command() returns any arguments that appear after the name of the application on the command line." ---- MSDN

for example (I will now use that lil` program):
1.> I will have to compile that program to a name... say for example: POPS.EXE

2.> Then I will use it like this, on the command line:
C:\> POPS Look ma! A parameter!!

---- This will popup a message box saying, "Look ma! A parameter!!" on your screen.

3.> On VB, I will code like this:
Shell "C:\POPS.EXE Look ma! A parameter!!",vbNormalFocus


for more info, search MSDN.
:D