如何在vba中运行MiniTab可执行文件(.mtb)

时间:2014-07-16 16:29:07

标签: vba excel-vba userform commandbutton minitab

我希望将其作为命令按钮合并到用户表单中。 我到目前为止尝试的代码:

Private Sub graphButton_Click()

    Dim mtbPath As String: mtbPath = "S:\MetLab (Protected)\MetLab Operations\Lab 
    Reports\Forgings"

    Call Shell(Environ$("COMSPEC") & " /s " & mtbPath & "\Updater.mtb", vbNormalFocus)

End Sub

其中Updater.mtb是我想要执行的实际文件。这似乎只打开命令提示符 - 这不是我正在寻找的

1 个答案:

答案 0 :(得分:1)

复制并粘贴到VBA模块中:

    Sub Run_Minitab_Macro()

    Set MtbApp = CreateObject("Mtb.Application")

    With MtbApp.ActiveProject
    'This lets you open an excel file from your desktop:
    .ExecuteCommand "WOpen 'C:\Users\you\Desktop\TEMP1.xlsx'; FType; Excel." 
    'Save the minitab project to my documents:
    .ExecuteCommand "Save  'C:\Users\you\My Documents\Test.MPJ'; Project; Replace."
    'On Error Resume Next
    .ExecuteCommand "%MacroFile" 'This is a .MAC macro file stored in the my 
                                 'documents folder saved to here, 
                                 'any command-line command can go here though
    'On Error GoTo 0
    .ExecuteCommand "Save."
    End With

    End Sub