问题1
vba代码中,怎样运行一个exe?是运行,不是生成。
比如有一个vba过程,在这个过程中我要运行扫雷游戏,怎么写代码?
问题2
-----------------------
Public Sub test1()
   call test2
   其他操作
End SubPublic Sub test2()
    if error then
       '退出所有test2,以及test1
    end if
End Sub
-----------------------
执行test1,会调用test2
调用test2时,如果发生error,end test2,返回test1时,也能立即end test1,不执行后面的其他操作。
如果没发生error,返回test1,正常执行其他操作。
怎么实现?

解决方案 »

  1.   

    1. VBA 代码中,仍然可以调用内部函数 Shell 来启动其它程序。2. 有两种方法:
     ①如果可能的话,用 End ,结束代码的执行。
     ②把 test2() 由 Sub 改为 Function 。这个肯定适用。
    Public Sub test1()
        If (test2()) Then Exit Sub
        其他操作
    End SubPublic Function test2() As Long
        ' 其它代码
        ' .........
        If Error Then
        '退出所有test2,以及test1
            test2 = 1
            Exit Function
        End If
        ' 其它代码
        ' ...............
        test2 = 0
    End Function