vb help plz

I did something about 5 years ago and cant seem to remember, im pretty sure it was some simple code, someone must know :o

Hybrids
 
Well I'm sure I'm missing the point here, but can you not just use the Shell command on the click of a button, or within your code :confused:
 
~J~ said:
Well I'm sure I'm missing the point here, but can you not just use the Shell command on the click of a button, or within your code :confused:

Ummmm, I'm not sure what you mean. Lets say ive just opened up excel, ive got the form tool bar open and ive just made a command button, which contains no code. I want to open a external program from this command button. What code would I need to input into this command button/macro??

Is there some vb code called run 'C:\myprogram.exe' or vb.open 'c:\myprogram.exe'

etc

Does this help at all?

Thanks Hybrids
 
This should work:

Code:
dim objApp

Set objApp = CreateObject("WScript.Shell")

objApp.run "yourprogram.exe"

Set objApp = Nothing

I only use vbscript with web apps; there might be something you need to put in that code to make it execute when the button is pressed.
 
This should do the trick.

Code:
Private Sub CommandButton1_Click()
Dim RetVal As Double

    RetVal = Shell("c:\windows\notepad.exe", vbNormalFocus)
End Sub
 
sfx said:
This should do the trick.

Code:
Private Sub CommandButton1_Click()
Dim RetVal As Double

    RetVal = Shell("c:\windows\notepad.exe", vbNormalFocus)
End Sub

Exactly what I was trying to say, couldn't get simpler than saying "Can't you use the Shell command" :p
 
Works a treat thanks guys!

Sorry about this but how about opening a file which is not .exe for example my3dmodel.par ?

I've tried replacing the c:\windows\notepad.exe with \my3dmodel.par but i get an error, I assume I need another command instead of shell?

Thanks

Hybrids
 
Nevermind managed to do some google searchs on the Shell command and found a similar example

Code:
Dim dTaskID As Double, path As String, file As String

path = "C:\program files\Solid Edge V16\Program\edge.exe"
file = "C:\part1.par"
dTaskID = Shell(path + " " + file, vbNormalFocus)

'MsgBox ("Program loaded")
End

It worked first time

Thanks for all your help :)

Hybrids
 
Hybrids said:
Nevermind managed to do some google searchs on the Shell command and found a similar example

Code:
Dim dTaskID As Double, path As String, file As String

path = "C:\program files\Solid Edge V16\Program\edge.exe"
file = "C:\part1.par"
dTaskID = Shell(path + " " + file, vbNormalFocus)

'MsgBox ("Program loaded")
End

Ok ive now come up with a slight problem ive created a folder in C: called "temp temp" ive put the part1.par into this folder and changed the code file = "C:\part1.par" to file = "C:\temp temp\part1.par" but for some strange reason the problem doesnt like this, if i take the space away from temp temp and change the folder name the program runs fine? Why does it not like the space? In the variable path using spaces doesnt seem to create any problems but in file it does?? Help

Thanks

Hybrids
 
nm I managed to solve it again but had to use new code,

Code:
Shell "C:\program files\Solid Edge V16\Program\edge.exe ""c:\temp temp\part1.par""", vbNormalFocus

Thanks again :p
 
Back
Top Bottom