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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a msg box that will open an executable 1

Status
Not open for further replies.

pbulko

Programmer
Jul 2, 2003
1
0
0
US
I am trying to develop a message box that when clicking yes - the user can open an executable. Is this possible - I can develop the code up to where it looks at the variable from what the user selects in the message box - but unsure how to call the executable (if possible) - thanks.
 
Sure, the code would look something like this:

UserAnswer = Msgbox (Question,4,"Launce program?")
If UserAnswer = 6 then
'Yes
rc% = Shell(Path & File .exe)
Else UserAnswer = 7 then
'NO
End If

Hope this is helpful,

Calculus
 
Hey Calculus, do you know how to get Extra! open a specific file once it has Shell's the program. e.g. Shell ("Excel.exe",1) then have it open a specific file.

Also,
Is there any better reference for this language you know of? The Help files are not very good and the code examples leave a lot to be desired.

Thanks, Scott
 
scottmh:
I was looking for answers to my question, and though I could help you with yours. Have you considered the ShellExecute API? It uses the same logic that Windows uses to associate a file to an application when you double click on it. Try the example below. The only annoting thing I've found with it is that it reuses already open instances of the called application. But it might work for you. Use the path to your own XLS file rather than 'C:\test.xls' - it works with .doc, you can pass it a url, etc...


Option Explicit

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal HWND As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long


Public Sub subNewShell(strFileToOpen As String)
Dim lngReturn As Long
lngReturn = ShellExecute(0, "open", strFileToOpen, vbNullString, vbNullString, 1)
End Sub

Public Sub Main()
Call subNewShell("C:\test.xls")
End Sub
 
scottmh:

Sorry, use "" instead of vbNullString for Extra Basic.
 
Drat, also forgot to remove the 'Public' keywords. This one will compile and run in Extra!

Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal HWND As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long


Sub subNewShell(strFileToOpen As String)
Dim lngReturn As Long
lngReturn = ShellExecute(0, "open", strFileToOpen, "", "", 1)
End Sub

Sub Main()
Call subNewShell("C:\test.xls")
End Sub
 
Sure:

rc% = Shell ("Excel.exe MyFile.xls",1)

Just use the space and file name. This works with most major programs that accept command line info.

calculus
 
falkkor13,

Thanks. This worked very well. Do you know if there someplace (web, book {w/ real exmaples) that explains this kind of VB intereaction between applications that I could use as a good reference? Also, where can you get material that explains things like the shell32.dll calls?

My end result to get to is to have a macro in Extra that pulls my reports, saves them into a .csv file, opens them, combines the data of two different .csv files, and has Excel format the way I want to.

I know....might as well ask for a million dollars, but, I like to poke around with this stuff for fun, and would like to learn it at the same time.

Anyway, thanks for your help.
Scott
 
Check out my FAQ on Excel/Extra. As for DLL's, check the web. Attachmate help files are pretty good if you dig through them.

calculus

AttachMate solutions
faq99-4069 How do I use VB(A) to manipulate attachmate (6.5+)?
faq99-4068 How do I get data to Excel?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top