linux脚本 等待命令完成,等待Shell完成,然后格式化单元格 - 同步执行命令

我有一个可执行文件,我使用shell命令调用:

Shell (ThisWorkbook.Path & "\ProcessData.exe")

可执行文件执行一些计算,然后将结果导出回Excel.我希望能够在导出后更改结果的格式.

换句话说,我首先需要Shell命令等待,直到可执行文件完成其任务,导出数据,然后执行下一个格式化命令.

我试过了Shellandwait(),但没有太多运气.

我有:

Sub Test()

ShellandWait (ThisWorkbook.Path & "\ProcessData.exe")

'Additional lines to format cells as needed

End Sub

不幸的是,格式化仍然在可执行文件完成之前进行.

仅供参考,这是我使用ShellandWait的完整代码

' Start the indicated program and wait for it

' to finish, hiding while we wait.

Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long

Private Const INFINITE = &HFFFF

Private Sub ShellAndWait(ByVal program_name As String)

Dim process_id As Long

Dim process_handle As Long

' Start the program.

On Error GoTo ShellError

process_id = Shell(program_name)

On Error GoTo 0

' Wait for the program to finish.

' Get the process handle.

process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)

If process_handle <> 0 Then

WaitForSingleObject process_handle, INFINITE

CloseHandle process_handle

End If

Exit Sub

ShellError:

MsgBox "Error starting task " & _

txtProgram.Text & vbCrLf & _

Err.Description, vbOKOnly Or vbExclamation, _

"Error"

End Sub

Sub ProcessData()

ShellAndWait (ThisWorkbook.Path & "\Datacleanup.exe")

Range("A2").Select

Range(Selection, Selection.End(xlToRight)).Select

Range(Selection, Selection.End(xlDown)).Select

With Selection

.HorizontalAlignment = xlLeft

.VerticalAlignment = xlTop

.WrapText = True

.Orientation = 0

.AddIndent = False

.IndentLevel = 0

.ShrinkToFit = False

.ReadingOrder = xlContext

.MergeCells = False

End With

Selection.Borders(xlDiagonalDown).LineStyle = xlNone

Selection.Borders(xlDiagonalUp).LineStyle = xlNone

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值