Excel下创建新进程且等待执行完成
2011-11-20 16:14
375 查看
Option Explicit
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Type TCell
Col As Long
Row As Long
End Type
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CommandButton1_Click()
Dim PID As Long
Dim hProcess As Long
Dim exitCode As Long
PID = Shell("c:\program files\winrar\winrar.exe", vbNormalFocus) '"c:\windows\notepad.exe"
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
Do
Call GetExitCodeProcess(hProcess, exitCode)
Sheet1.Cells(2, 1) = Now
Sleep 1000
DoEvents
Loop While exitCode <> 0
Call CloseHandle(hProcess)
MsgBox "You have closed the notepad!", vbOKOnly, "Hello, Buddy!"
End Sub
Private Sub CommandButton2_Click()
Dim vCell(20) As TCell
Dim i As Integer
Dim n As Integer
For i = 0 To 9
vCell(i).Col = i + 1
vCell(i).Row = 20
Next i
For i = 10 To 19
vCell(i).Col = 20 - i
vCell(i).Row = 21
Next i
While 1 > 0
n = 19
For i = 0 To 19
Sheet1.Range(Sheet1.Cells(vCell(i).Row, vCell(i).Col), Sheet1.Cells(vCell(i).Row, vCell(i).Col)).Interior.Color = 400
Sheet1.Range(Sheet1.Cells(vCell(n).Row, vCell(n).Col), Sheet1.Cells(vCell(n).Row, vCell(n).Col)).Interior.Color = 16777215
'Sheet1.Cells(vCell(i).Row, vCell(i).Col) = i + 1
n = i
If Sheet1.Cells(1, 1) <> "" Then Exit Sub
Sleep 350
DoEvents
Next i
Sheet1.Range(Sheet1.Cells(vCell(19).Row, vCell(19).Col), Sheet1.Cells(vCell(19).Row, vCell(19).Col)).Interior.Color = 16777215
Wend
End Sub
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Type TCell
Col As Long
Row As Long
End Type
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CommandButton1_Click()
Dim PID As Long
Dim hProcess As Long
Dim exitCode As Long
PID = Shell("c:\program files\winrar\winrar.exe", vbNormalFocus) '"c:\windows\notepad.exe"
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
Do
Call GetExitCodeProcess(hProcess, exitCode)
Sheet1.Cells(2, 1) = Now
Sleep 1000
DoEvents
Loop While exitCode <> 0
Call CloseHandle(hProcess)
MsgBox "You have closed the notepad!", vbOKOnly, "Hello, Buddy!"
End Sub
Private Sub CommandButton2_Click()
Dim vCell(20) As TCell
Dim i As Integer
Dim n As Integer
For i = 0 To 9
vCell(i).Col = i + 1
vCell(i).Row = 20
Next i
For i = 10 To 19
vCell(i).Col = 20 - i
vCell(i).Row = 21
Next i
While 1 > 0
n = 19
For i = 0 To 19
Sheet1.Range(Sheet1.Cells(vCell(i).Row, vCell(i).Col), Sheet1.Cells(vCell(i).Row, vCell(i).Col)).Interior.Color = 400
Sheet1.Range(Sheet1.Cells(vCell(n).Row, vCell(n).Col), Sheet1.Cells(vCell(n).Row, vCell(n).Col)).Interior.Color = 16777215
'Sheet1.Cells(vCell(i).Row, vCell(i).Col) = i + 1
n = i
If Sheet1.Cells(1, 1) <> "" Then Exit Sub
Sleep 350
DoEvents
Next i
Sheet1.Range(Sheet1.Cells(vCell(19).Row, vCell(19).Col), Sheet1.Cells(vCell(19).Row, vCell(19).Col)).Interior.Color = 16777215
Wend
End Sub
相关文章推荐
- .Net最简单的创建多线程主线程等待所有线程执行完成的例子
- 执行并等待进程完成
- C程序完成:父进程创建一个子进程,父进程对子进程设置一个报警信号,然后父进程等待子进程的结束,如果此时报警信号先到,就终止子进程。
- Linux内核源代码情景分析-进程的创建,执行,等待,消亡
- Linux操作系统分析-lab2-进程的创建与可执行程序的加载
- 进程的创建、等待与终止
- 创建进程并在某段时间后执行方法
- Linux-进程描述(4)之进程优先级与进程创建执行
- VC++ 创建进程并等待其退出
- 关于fork&exec之进程的创建和可执行程序的加载过程
- 进程的创建与可执行程序的加载
- 进程的创建与可执行程序的加载
- 使用VC创建进程和执行命令行程序的方法
- java线程池主线程等待子线程执行完成
- PB用OLE创建Excel后,退出程序后excel.exe进程还在
- Java外部执行操作系统命令(Java 创建本地系统进程)
- 主线程等待子线程全部执行完成
- zygote通过包装fork完成activity(linux下进程)创建
- 第8节进程创建和执行
- 进程控制【创建、等待、终止和替换】