Ti allego il codice da inserire in un modulo:
Poi in un eventuale pulsante, per provare:codice:Option Explicit Public Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Public Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadID As Long End Type Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal _ hHandle As Long, ByVal dwMilliseconds As Long) As Long Public Declare Function CreateProcessA Lib "kernel32" (ByVal _ lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _ lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _ ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _ ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _ lpStartupInfo As STARTUPINFO, lpProcessInformation As _ PROCESS_INFORMATION) As Long Public Declare Function CloseHandle Lib "kernel32" (ByVal _ hObject As Long) As Long Public Const NORMAL_PRIORITY_CLASS = &H20& Public Const INFINITE = -1& '######################################################### 'Funzione per lanciare un programma in sincrono. 'Il programma lanciato in finestra viene 'atteso' per 'tutta la sua durata. 'Una funzione usata per lanciare un programma MS-DOS 'e attendere la sua fine. '1998 by Berardi Paolo 'Email pberardi@nt.kjws.com '######################################################### Public Sub ShellAndWait(ByVal RunProg As String) Dim RetVal As Long Dim proc As PROCESS_INFORMATION Dim StartInf As STARTUPINFO StartInf.cb = Len(StartInf) 'Crea sessione del programma da lanciare RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc) RetVal = WaitForSingleObject(proc.hProcess, INFINITE) RetVal = CloseHandle(proc.hProcess) End Sub
Vorrei segnalare che non è farina del mio sacco.. un po' di tempo fa l'ho scaricato/trovato su internet e uso questa funzione così com'è!codice:Private Sub Command1_Click() ShellAndWait ("Calc.exe") MsgBox ("Calcolatrice Chiusa!") End Sub
Ciao

Rispondi quotando