Public Sub SendStringNoRead(abc As String) Dim strProgramName As String strProgramName = Application.ActiveWorkbook.Path & "\ConsoleApp.exe " & abc ShellRun (strProgramName) End Sub
'网上搜到的实现 Public Function ShellRun(sCmd As String) As String
'Run a shell command, returning the output as a string
Dim oShell As Object Set oShell = CreateObject("WScript.Shell")
'run command Dim oExec As Object Dim oOutput As Object Set oExec = oShell.Exec(sCmd) Set oOutput = oExec.StdOut
'handle the results as they are written to and read from the StdOut object Dim s As String Dim sLine As String While Not oOutput.AtEndOfStream sLine = oOutput.ReadLine If sLine <> "" Then s = s & sLine & vbCrLf Wend
ShellRun = s
End Function
SendStringNoRead这个函数的功能是
接收单击单元格的值-就是输入参数
给出 exe 的路径 并把 命令行参数拼上去
调用函数 ShellRun 实现exe执行
-3.4- Excel单击发送的实现
在对应的 Sheet对象上双击
选择 Worksheet 中的 SelectionChange
键入下面的代码
1 2 3 4 5 6 7 8 9
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Column = 11 Then If Target.Count = 1 Then If Target.Value <> "" Then SendStringNoRead (Target.Value) End If End If End If End Sub