Sub DetectExcel()
'该过程检测并登记正在运行的 Excel。
Const WM_USER = 1024
Dim hwnd As Long
'如果 Excel 在运行,则该 API 调用将返回其句柄。
hwnd = FindWindow("XLMAIN", 0)
If hwnd = 0 Then '0 表示没有 Excel 在运行。
Exit Sub
Else
'Excel 在运行,因此可以使用 SendMessage API
'函数将其放入运行对象表。
SendMessage hwnd, &H10, 0, 0
End If
End Sub
'该过程检测并登记正在运行的 Excel。
Const WM_USER = 1024
Dim hwnd As Long
'如果 Excel 在运行,则该 API 调用将返回其句柄。
hwnd = FindWindow("XLMAIN", 0)
If hwnd = 0 Then '0 表示没有 Excel 在运行。
Exit Sub
Else
'Excel 在运行,因此可以使用 SendMessage API
'函数将其放入运行对象表。
SendMessage hwnd, &H10, 0, 0
End If
End Sub
set ox=createobject("excel.application")
...
ox.quit
set ox=nothing
xlapp.Visible = True '让该应用程序可见
xlapp.SheetsInNewWorkbook = 1
Set xlbook = xlapp.Workbooks.Add
With xlapp.ActiveSheet.Range(X).Borders '边框设置
.LineStyle = xlBorderLineStyleContinuous
.ColorIndex = 1
End With
....
xlsheet.application.quit
Set xlsheet = Nothing
-----------
不过如果反复调用删除excel进程的话,会造成改进程在内存中因无法得到删除而出错,解决办法,只有重起机器了.