API run program

  • Thread starter Thread starter Johan
  • Start date Start date
J

Johan

i am new to programming.
I want to run a program and if it gives an error the OK button should be
pressed automaticly

Any help to this???

I know that I must use API but how to I activate API in excel?
 
Hi,

Please give us more info on what you are doing, like the code. For one
thing, you don't need to call an API to click an OK button. You should just
build in an error trap, an error handler to deal with the error, and that can
all be done in Excel.
 
Something like this is my code:

Dim Shell
Set Shell = CreateObject("WScript.Shell")
Shell.Run "c:\battest\vbimport", 1
SendKeys "{enter}"

The file vbimport gives an error, and I want to send the key Enter to the
message box.

Thanks
ShaneDevenshire skrev:
 
The problem is that the code moves on before I got the error code, How do I
get the code to wait

Sheeloo skrev:
 
Here is the complete code
Sub testSendKeys()
Dim ReturnValue
ReturnValue = Shell(c:\battest\vbimport,1)
AppActivate ReturnValue
SendKeys "~" , TRUE
End Sub
 
Thanks but now I got an error on this line:
ReturnValue = Shell("c:\battest\vbimport", 1)

saying:
Object does not support this property or metode

Hope you can help the beginner!!!

Thanks
Johan
Sheeloo skrev:
 
I manage to create focus to the program, but when I send the key nothing is
happening.

Any help?

Johan

Johan skrev:
 
I started with the following example given in Help
=============
Sub test1()
Dim ReturnValue, I
ReturnValue = Shell("notepad.EXE", 1)
AppActivate ReturnValue
For I = 1 To 60
SendKeys I, True
Next I
SendKeys "~", True
For I = 1 To 30
SendKeys I, True
Next I
SendKeys "%{F4}", True
SendKeys "~", True
End Sub
=============
Suggest you test with Notepad and play around
 
Thank you, but I can not work this out.
When I run your program it does not send anything to notepad.


Sheeloo skrev:
 
Working for me...
I have Excel 2003 and put the code in the module for my workbook...
Where are you putting this code in?
 
Thank you, I did copy the sub to a Module and not ThisWorkbook

Next question, if tou can help me on this, how du I start the other program
from a shortcut. I need that because the shortcut makes an automaticaly
import to the program. It is not possible to do this by strating the
"program" (.exe file).

Sheeloo skrev:
 
Go to the shortcut, right-click and choose properties.
Copy the text in the Target box.

Replace the program name with the copied text in your VBA program...
 

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