我要从excel打开Sketchup,然后运行一个插件,我使用下面的代码打开Sketchup,然后使用SendKeys选择插件。
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Sub fLaunchProgram(ByVal sProgram As String)
Dim ProcessHandle As Long
Dim ProcessId As Long
On Error GoTo errExit
ProcessId = Shell(sProgram, vbNormalFocus)
ProcessHandle = OpenProcess(&H1F0000, 0, ProcessId)
WaitForSingleObject ProcessHandle, INFINITE
Exit Sub
errExit:
MsgBox "External program " & sProgram & " was not found", vbCritical, " fLaunchProgram"
End Sub
'To load SU
Sub pTest()
fLaunchProgram ("C:\Program Files\SketchUp\SketchUp 2015\SketchUp.exe")
End Sub
Sub Button1_Click()
pTest
SendKeys "~ (tilde)"
SendKeys "%{left}{DOWN}n~"
SendKeys "%x{DOWN}~"
SendKeys "{NUMLOCK}", True
SendKeys "%fx"
SendKeys "n"
End Sub
最后一行代表Alt-File-Exit,然后弹出msgbox,n应该代表“ no”,程序应该关闭,它不能识别“ n”代表“ no”
答案 0 :(得分:0)
自SketchUp 2015起,SketchUp Ruby API中有一个Model#close模型。如果使用true作为参数调用,它将忽略更改。它不会关闭应用程序,但会带您进入一种状态,可以关闭应用程序而无需担心保存显示内容。
答案 1 :(得分:0)
这应该有效:
Shell "taskkill /F /IM sketchup.exe", vbNormalFocus
如此处所示:
以及此答案的后半部分:
答案 2 :(得分:0)
在Excel中启动流程时,您可以从OpenProcess
获取启动的 processID 。您也可以导入TerminateProcess
并使用从OpenProcess
获得的 processID 关闭(终止)它。