Open another program sing VBA

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Hi all,

I would like to open another program, (MYOB), by clicking its picture that
I've pasted to a worksheet. I know how to assign a macro to the picture but
I'm having difficulties in writing the macro to execute the MYOB program.

Rob
 
Hi Rob,

Right-click the picture and assign a hyperlink to it.

Ed Ferrero
 
Thanks for your quick response, Ed. That certainly works great, but I also
want a little bit of control over this procedure, eg if the program is
already open then I don't want the hyperlink to work. And also another
example, where I want to have the option to proceed with the hyperlink or
not depenfding on certain circumstances.
In other words I would rather use VBA to go to open another program so that
I can have control over when that program might be opened.

Can you help with that?

Rob
 
What do you mean by a program, as you run a procedure, not open it? Do you
mean open another workbook?

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
As per my first posting, I'm trying to open a program called MYOB (an
accounting program), not another workbook. (It's not a microsoft pgm.)
Basically put...
I need some code that will start up that MYOB program and the related file.
The reason I want this as code is that a hyperlink can open up more than one
instance of a program which I want to prevent and, I also want to do some
other stuff before the code executes the opening of the MYOB program.
The full path to the MYOB program file is:
K:\0000\MYOB\Data\xxx.prm

(I've looked through help, etc., but cannot seem to locate any instruction
on how to open a program other than a microsoft program.)

Rob
 
Shell it. Look up shell in VBA help.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks Bob,
From the help I was able to run the following....

Sub OpenMYOB()
Dim ReturnValue
MyAppID = Shell("D:\Program Files\Myob Premier Trial\Myobp.exe", 1)
AppActivate MyAppID 'Activate MYOB
End Sub
(although I don't understand why ReturnValue is dimmed.)

However, even though this starts the MYOB program OK I would like the actual
MYOB data file to open with it, (just as you would when you click an Excel
file which Opens Excel and then displays the Excel file as well.)

Can you help with that or point me in the right direction?
(As I said previously the path to the MYOB file I wish to open is
K:\0000\MYOB\Data\xxx.prm)

Thanks so far!
Rob
 
Sub OpenMYOB()
Dim ReturnValue
MyAppID = Shell("D:\Program Files\Myob Premier Trial\Myobp.exe", 1)
AppActivate MyAppID 'Activate MYOB
End Sub
(although I don't understand why ReturnValue is dimmed.)

In my help, it sets the RetVal to the result of the shell operation, to
check success or not.
However, even though this starts the MYOB program OK I would like the actual
MYOB data file to open with it, (just as you would when you click an Excel
file which Opens Excel and then displays the Excel file as well.)

You can do that by passing the file as an argument to the executable, like
this with Notepad

Shell "notepad.exe c:\mytest\code.txt", 1

So I guess yours would be

MyAppID = Shell("D:\Program Files\Myob Premier Trial\Myobp.exe
D:\myfiles\myfile.myp", 1)

or something similar
 
Thanks again Bob, but I'm not getting anywhere with this.
I only get the program to load, and not the data file with it.
What I've tried is:

Shell "D:\Program Files\Myob Premier Trial\Myobp.exe D:\FOLA\Myob\FOLA Feb
05.prm", 1

MyAppID = Shell("D:\Program Files\Myob Premier Trial\Myobp.exe
D:\FOLA\Myob\FOLA Feb 05.prm", 1)

I can't think of another way to do this. Any ideas? If it can't be done, I
can live with that as I'm fairly happy that it at least runs the MYOB
program.

Also, could you suggest a way to test to see if the MYOB prgm is already
running, and if so, to exit the sub?

Rob
 
Hi Rob,

Most (but not all) programs allow you to specify a file to open on the
command line, but not all. If they do that shell technique should work.
Unfortunately, I don't have that app to test myself.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks foryour input Bob!

Rob

Bob Phillips said:
Hi Rob,

Most (but not all) programs allow you to specify a file to open on the
command line, but not all. If they do that shell technique should work.
Unfortunately, I don't have that app to test myself.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top