MTBridge Engine : How To

 

 

 

Legend

 

        Video Available          Video Not Available                                              New in 2.5 version     Improved in 2.5 version

      Minitab 15 with MTBEngine toolbar                                                              VB or    VBA or    vbScript callable Functions     

 

 

 

The 2.5 Engine works as:

         StandAlone Exe ( The engine manages Minitab and Excel - our preferred )  

         Minitab Addin ( Minitab manages Excel)  

         Excel Addin (Excel manages Minitab)            Excel 2007 Addin (Excel manages Minitab)

  

 

Using Minitab History to auto create a ready to run vbScript : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

       One of the most interesting feature of 2.5 version.  Like Excel < Record New Macro > command

 

         AutoScript of User Command Sequence

         AutoScript of a vbScript Procedure Sequence ( 4 min. video )

 

 

Translate your Minitab History into a sequence of COM commands

 

        With MTBEngine you can have immediately all your History Commands translated in equivalent COM Commands

 

 

Auto Create a PowerPoint Report  using Minitab Graphs

 

        Easy as 1 2 3 ... ( Note : this operation is much faster than you see in this video because of recording video use ... )

 

              Why graphs are redraw before to be saved ?.

              Because Minitab COM Graph Object has a big Error ( you can crash your system if you try to use this Object on a previous saved project,

              while it works fine on new project / graphs ) .  MTBEngine bypass this problem using Windows API, not COM commands, but it needs to

              redraw all the graphs.

 

 

View a Keith Bower  [ excellent ] video 

 

        View a Keith Bower  YouTube [ ©  Keith Bower ] video by macro or by menu.

              This example requires two of best MTBEngine features < Enhanced Macros Command > and < Universal Macro Dialog (UMD) >            

 

 

Universal Minitab Macro Dialog (UMD)  - I  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        This feature is probably one of those you would like to have in the next Minitab version.  

 

              Stop running a macro using the %macro command line and keeping in mind all the parameters to pass ... ( not so easy )   

              Begin to use all the downloadable macros available @ Minitab site

 

 

Universal Minitab Macro Dialog (UMD)  - II  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        This feature is probably one of those you would like to have in the next Minitab version.

              Easy as 1 2 3 :

  • Download your preferred macro file ( mac file ) from Minitab site

  • You can use the macro in Session Window as suggested by Minitab ( %filemacro parameters .. ) , but it is better ...

  • Edit the macro using MTBEngine Macro Editor

  • Insert two pairs of reserved words ( used by MTBEngine ) in the right position.

  • Save the mac file.

  • Run the macro file by menu command or by the same Macro Editor

  • All done ... Now you can use this macro as shown in the video

 

Universal Minitab Macro Dialog (UMD)  - III  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        This feature is probably one of those you would like to have in the next Minitab version.   

 

              You can test the macro examples and/or read related Minitab documents published in Minitab site Macros pages, in real time.

              Only the mac file must be present on your PC.

              Please see these links : Data Example , Documentation for more information.

              ( Note : this operation / macro is much faster than you see in this video because of recording video use ... )

 

 

Universal Minitab Macro Dialog (UMD)  - IV  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        This feature is probably one of those you would like to have in the next Minitab version.

     

              How many times have you forgotten to open the right worksheet before to run a Minitab Dialog Command ?

              With UMD you haven't this problem

 

 

 

R Language to Minitab  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        All the standard Minitab Commands (Procedures) + hundred of Minitab available macros, now easy usable with our UMD utility,

              are not enough  for your needs ?  Don't worry !!

 

              MTBridge Engine manages the R Language © functions using the excellent Thomas Baier and Erich Neuwirth (D)COM Server !!

              With our mEngine.DLL plus the (D)COM Server [ © StatConn ] you will have all the additional power of R Language in your Minitab

 

 

 

SciLab to Minitab  : WE ANTICIPATE THE SOLUTION OF YOUR NEEDS

 

        All the standard Minitab Commands (Procedures) + hundred of Minitab available macros, now easy usable with our UMD utility,

              are not enough  for your Math needs ?  Don't worry !!

 

              MTBridge Engine manages the SciLab © functions using the excellent Thomas Baier and Erich Neuwirth SciLab Proxy DLL !!

              With our mEngine.DLL plus the SciProxy.DLL [ © StatConn ] you will have all the additional math power of SciLab in your Minitab

             

 

Customize the MTBEngine Toolbar Menu

 

        Simply editing a INI file you can customize the MTBEngine Toolbar Menu as you want

     

 

 

Run a Minitab procedure from software tool other than Excel - I

Customize Training Documents Example

 

        This video shows how to customized your Training Documents . This example uses one of the excellent Minitab Chooser [ © Minitab Inc ]

              PDFs really well done and useful,  but  with MTBEngine you can do something better.

  • Open a PDF Document with your preferred PDF Editor

  • Insert a Button Command where you want ...

  • Add a prepared vbscript file as Button Action

  • Test  the action

  • Save the PDF file.

        All done ... Now can use this PDF document as shown in this  second video

 

 

Enhanced Macros Command - I

Call external DLLs Functions using a traditional Minitab macro 

 

        This video shows how to call the Microsoft SAPI Voice, passing the string values as Konstants,  by a traditional Minitab macro

 

 

Enhanced Macros Command - II

Run a Excel Macro using a traditional Minitab macro 

 

        This video shows how to run a VBA Code from your Minitab session window.

             ( Minitab_And_Excel_Simple_Chat Public Sub is fully documented here )

 

 

Enhanced Macros Command - III

Run third part Excel Addin using a traditional Minitab macro 

 

        This video shows how to run a VBA Code and third part Excel Addin from your Minitab session window.

              The xls used in this video example is exactly the Tolerance Analysis: Gear Pump Assembly Optimization  file (1 year old, without any

              modification) available @  http://www.palisade.com/industry/SixSigmaModels.asp

 

              Q&A : Only @Risk5.x addin can be joined to Minitab using MTBEngine ? I have Crystal Ball for my DFSS analyses or Risk simulations !!

                        Look @ this code and video

 

 

Enhanced Macros Command - IV

Get a result  from a VBA Public Function or  from a DLL Exported Function and use it as input value into a traditional Minitab macro 

 

          Yes, it is possible. Call us for more info or look @ this old version 2.0 example to understand the power of this feature

 

 

SQL Queries Automation Example

 

        The video shows the use of a vbscript to realize some queries managed by the MTBEngine Toolbar Commands and / or managed

              by a web page (html file)

              (The data file used to register this video is the original ProcessData.mdb [ © Minitab Inc ] available @ Minitab Macro Training)

 

 

Real Time Minitab Analysis Automation Example

 

        This video shows a GSummary Command Automation of incoming data ( a batch file is used to simulate the CMM real time data generation)

 

 

 

 

 

[Partial List] Internal MTBridge Engine Functions :

VBA, VB and vbScript (with minor changes) callable 

 

Option Explicit


Declare Function XMtbObject Lib "m_Engine.DLL" (ByVal hwnd As Long, ByRef mObj As Object) As Long
Global MtbApp As Mtb.Application
Global m_me As Long

Global x_me As Long

 

' *********************************************************************************

' PUT

' Function mFastPut_NewCol(xSourceRange As String, xSheet As String) As Long

' Function mPutNumArr_NewCol(NumArr() As Double) As Long

' Function mPutDateArr_NewCol(DateArr() As Date) As Long

' Function cPut_SafeDate_NewCol(xSourceRange As String, xSheet As String) As Long

' Function cPut_To(vIn_xColRange As Variant, ByVal mColDest As Variant, ByVal mSheetDest As Variant) As Long

' Function cPut_NewCol(vIn_xCol As Variant) As Long

' *********************************************************************************

' GET

' Function cGet_ICol(OutColData As Variant, ByVal c As Long) As Long

' Function mGetData(vOutArray As Variant, ByVal mColSource As Variant, ByVal mSheetSource As Variant) As Long

' Function cGet_To(ByVal xCol As String, ByVal xSheet As String, ByVal mCol As Variant, ByVal mSheet As Variant) As Long

' Function cGet_ToXName(ByVal xname As String, ByVal mColSource As Variant, ByVal mSheetSource As Variant) As Long

' *********************************************************************************

' MATRICES

' Function mPut_New(vAreaData As Variant) As Long Function mPut_New_DArray(NumArr() As Double) As Long

' Function mGet_as_xArray(matrix As Variant, xArray() As Double) As Long

' Function mGet_as_xName(matrix As Variant, xname As String) As Long

' Function mGet_as_xRange(matrix As Variant, xrange As String) As Long

' *********************************************************************************

' COMMAND OUTPUTS

' Function mCommand_Last(MtbCommand As Object) As Long Function mOutputs_Last(MtbOutputs As Object) As Long

' Function mCommandOutputs_Last_PutTo(ByVal IO As Long, ByVal xSheet As String, ByVal xRange As String) As Long

' Function mCommand_I(num As Long, MtbCommand As Object) As Long

' Function mOutputs_I(ByVal num As Long, MtbOutputs As Object) As Long

' Function mCommandOutputs_I_PutTo(ByVal IC As Long, ByVal IO As Long, ByVal xSheet As String, ByVal xRange As String) As Long

' *********************************************************************************
 

 

Initialize Minitab and Excel in MTBridge Engine Shared Memory

 

Sub xmCreate() 
     If IsObject(MtbApp) Then
          If m_me Then
          Else
              x_me = Application.hwnd
              m_me = XMtbObject(x_me, MtbApp)
              If m_me Then InitMe MtbApp, Application
          End If
     End If
End Sub

 

 

Check Minitab Object and Excel Object

 

Sub HowTo_Check_Minitab()
Dim Title As String, Msg As String
 

       If x_me Then Else xmCreate ' to initialize
       Title = "I am " & ThisWorkbook.name & ", a Excel workbook, and my companion is .."
       With MtbApp
             Msg = "Minitab" & vbCrLf & vbCrLf & _
             "Status = " & .Status & vbCrLf & _
             "LastError = " & .LastError & vbCrLf & _
             "Default File Path = " & .Options.DefaultFilePath & vbCrLf & _
             "Application Path = " & .AppPath & vbCrLf & _
             "Window Handle = " & .Handle
        End With
        WINTOTOP x_me ' or Application.hwnd
       
MsgBox Msg, , Title
End Sub
 

 

Get a Minitab Column and put it on Excel Range/Sheet

 

Sub HowTo_Get_To()
Const xDestSheet = "sheet1"
Const xCol = 10
Dim n As Long, xDestCol As String
Dim mSourceCol As Variant, mSourceSheet As Variant
        mSourceCol = "m_Double": mSourceSheet = 1
      
 'mSourceCol = "m_String": mSourceSheet = 1
        'mSourceCol = "m_Date": mSourceSheet = 1


        ' If x_me Then Else xmCreate ' only if not initialized
        Application.ScreenUpdating = False
        For n = 1 To nTimes ' only for more tests
             xDestCol = LongTo_xColString(xCol + n)
            cGet_To xDestCol, xDestSheet, mSourceCol, mSourceSheet
        Next
        Application.ScreenUpdating = True
End Sub

 

 

Get a Minitab Column and put on Excel Name

 

Sub HowTo_GetTo_XName()
Dim xname As String
Dim mSourceCol As Variant, mSourceSheet As Variant
        mSourceCol = "m_Double": mSourceSheet = 1: xname = "My_Double"

        'mSourceCol = "m_String": mSourceSheet = 1: xName = "My_String"
        'mSourceCol = "m_Date": mSourceSheet = 1: xName = "My_Date"


        'If x_me Then Else xmCreate ' only if not initialized
       cGet_ToXName xname, mSourceCol, mSourceSheet
End Sub
 

 

Get a Excel Date Range and FastPut it on a New Minitab Column

 

Sub HowTo_mFastPut_NewCol()
Const xSourceSheet = "sheet1"
Dim xSourceRange As String
         xSourceRange = "A2:A101" 'num (Double) test
        
'xSourceRange = "B2:B101" 'text (String) test
'        '
xSourceRange = "C2:C101" 'date (Date) test  
'Minitab15 COM has a big "Lack of Fit" on it  

       'If x_me Then Else xmCreate ' only if not initialized
       mFastPut_NewCol xSourceRange, xSourceSheet
End Sub
 

 

Get a Excel Date Range and SafePut it on a New Minitab Column

 

Sub HowTo_mSafeDatePut_NewCol()

' Use this code instead of mFastPut_NewCol
Const xSourceSheet = "sheet1"
Dim xSourceRange As String: xSourceRange = "C2:C101"


       ' If x_me Then Else xmCreate ' only if not initialized
       cPut_SafeDate_NewCol xSourceRange, xSourceSheet
End Sub
 

 

Get a Excel Range and put it on a Minitab Column/Worksheet

 

Sub HowTo_cPut_To()
Dim n As Long
Const xSourceSheet = "sheet1"
Dim xSourceRange As String

        xSourceRange = "A2:A101" 'num (Double) test
        'xSourceRange = "B2:B101" 'text (String) test
        'xSourceRange = "C2:C101" 'date (Date) test  
'Minitab15 COM has a big "Lack of Fit" on it  

 

Dim mDestCol As Variant, mDestSheet As Variant
        mDestSheet = "Worksheet 1": mDestCol = 0
      
 'mSheet = 1: mCol = 0

        'mSheet = "": mCol = 0
        'mSheet = "": mCol = ""

Dim vColData As Variant


       'If x_me Then Else xmCreate ' only if not initialized
       For n = 1 To nTimes ' only for more tests
            vColData = Sheets(xSourceSheet).Range(xSourceRange).value
            cPut_To vColData, mDestCol, mDestSheet
       Next
End Sub
 

 

Get a Excel Range and put it on Minitab New Column

 

Sub HowTo_cPut_NewCol()
Dim n As Long
Const xSourceSheet = "sheet1"
Dim xSourceRange As String
        xSourceRange = "A2:A101" 'num (Double) test
       
'xSourceRange = "B2:B101" 'text (String) test
'       '
xSourceRange = "C2:C101" 'date (Date) test  
'Minitab15 COM has a big "Lack of Fit" on it  

 

Dim vColData As Variant

       'If x_me Then Else xmCreate ' only if not initialized
       For n = 1 To nTimes ' only for more tests
             vColData = Sheets(xSourceSheet).Range(xSourceRange).value
            cPut_NewCol vColData
       Next
End Sub
 

 

Get a Excel Range and use it as Minitab Matrix

 

Sub HowTo_PutAsMatrix()
Dim vAreaData As Variant
Dim xSourceSheet As String: xSourceSheet = "sheet2"
Dim xSourceRange As String: xSourceRange = "E2:H4"


       ' If x_me Then Else xmCreate ' only if not initialized
        vAreaData = Sheets(xSourceSheet).Range(xSourceRange).value
       mPut_New (vAreaData)
End Sub

 

 

Get a Minitab Last Command Output and put it on Excel range/sheet

 

Sub HowTo_LastCommandOutputs()

Const xDestSheet = "sheet2"

Const xDestRange = "E20"

Dim IOutput As Long : IOutput_to_Get = 2

      'If x_me Then Else xmCreate ' only if not initialized

      mCommandOutputs_Last_PutTo IOutput_to_Get, xDestSheet, xDestRange 

End Sub

 

 

 

Building a Chat between Excel and Minitab step by step

Full Code

 

Attribute VB_Name = "ChatModule"   

'*****************************************************  
' File : MTBridge Engine vba Example - 2.5 version
' Author: (c) Franco Anzani
' Copyright : SixSigmaIn Team http://www.sixsigmain.it

'******************************************************
'
'******************************************************
Option Explicit


Declare Function XMtbObject Lib "m_Engine.dll" (ByVal hwnd As Long, ByRef mobj As Object) As Long
Declare Sub WIN_SPEECH Lib "m_Engine.dll" (sVoice As String, sTitle As String)
Declare Sub TILE2VERTICAL Lib "m_Engine.dll" (ByVal hwnd As Long)
'************************************************************************************
Dim x_me As Long
Dim m_me As Long
Dim MtbApp As Mtb.Application
 

Dim MtbProject As Mtb.Project
Dim MtbUI As Mtb.UserInterface

Const ThisSheet = "NewChat"    

Const DataSheet = "BossData"    
Const IC_ItemsEls = 100
Const xg_shift = 23
Dim xRowOut As Long

Dim ic_hist_mean As Double
Dim ic_hist_StDev As Double
Dim ic_lsl As Double
Dim ic_usl As Double
Dim ic_mtb_mean As Double
Dim ic_mtb_StDev As Double
'************************************************************************************

Sub Minitab_And_Excel_Simple_Chat()

       If x_me Then Else xmCreate ' initialize Minitab and Excel in MTBEngine Common Shared Memory
       TILE2VERTICAL x_me  ' set this job as two vertical windows

       'Optional , only to clean a previous active project ' mtbApp.ActiveProject.ExecuteCommand "New." '; Project."
       Set MtbProject = MtbApp.ActiveProject
       Set MtbUI = MtbApp.UserInterface

        Sheets.Add   ' add Excel new sheet
        ActiveSheet.Name = ThisSheet
        Range("A1").Select: xRowOut = 1

       Sheets(DataSheet).Activate
       With Sheets(DataSheet)  'get historical / limit values
             ic_hist_mean = .Range("E2").Value
             ic_hist_StDev = .Range("E3").Value
             ic_lsl = .Range("E4").Value
             ic_usl = .Range("E5").Value
        End With

      With MtbUI  ' start Minitab/user Interface
           .Visible = True
           .OutputWindow.CommandsEnabled = False
           Chat_Open  ' start chat
           Chat_Body
           Chat_End
          .OutputWindow.CommandsEnabled = True
      End With
End Sub

 

Sub Chat_Open()
        Excel_Thinks "Today my Boss ... Marco, ... has given to me some new design and production data related to " _
        & "< Gear housing center distance >, in short named <_Ic > ... "


        Excel_Thinks "This is one of the pump design parameters ... " _
        & "After assembling the pump parts, a GAP between the blocks must not be present ..." _
        & "The GAP's Cpk is a value used as gear pump performance index."


        Excel_Thinks "My Boss declares that with this new _Ic range setup " _
        & "we can save up to 1 dollars for every assembled gear pump ... " _
        & "He has asked me to validate immediately these data, " _
        & "because he wants to start, as soon as possible, " _
        & "the gear pump's production with this new < _Ic specification >."


        Excel_Thinks "I have some doubts, ... " _
        & "The _Ic hystorical mean is " & Format(ic_hist_mean, "###0.000") & " , " _
        & "with a standard deviation of " & Format(ic_hist_StDev, "###0.000") & " ... " _
        & "In addition, the Gap value of our assembled gear pump have to meet the Purchase Specifications of our main Customer ... " _
        & "I don't know how I can analyze these data ... "


        Excel_Thinks "I am concerned, ... my statistical knowledge < is not robust >!!"
End Sub

Sub Chat_Body()

Dim m_command As String


        Sheets(ThisSheet).Activate

        Excel_Says "hey Minitab, ... I would like to use your statistic capabilities on my data .. May I ??"
       
Minitab_Says "Yes, you can .. I am waiting for your data ..."
        Excel_Says "I am sending my Boss data ... "

       mFastPut_NewCol "A2:A101", DataSheet, "_Ic"   ' Put Excel data to Minitab worksheet : 1 line of code

       m_command = "Describe '_Ic'; Mean."

       MtbProject.ExecuteCommand m_command
       mCommandOutputs_Last_PutTo 2, ThisSheet, "A" + LTrim$(Str$(xRowOut))  
' get Minitab Session Output : 1 line of code
       ic_mtb_mean = Val(Sheets(ThisSheet).Range("B" & LTrim$(Str$(xRowOut + 1))).Value)

       xRowOut = xRowOut + 2
       m_command = "Describe '_Ic'; StDeviation."

       MtbProject.ExecuteCommand m_command
       mCommandOutputs_Last_PutTo 2, ThisSheet, "A" + LTrim$(Str$(xRowOut)) 
' get Minitab Session Output : 1 line of code
       ic_mtb_StDev = Val(Sheets(ThisSheet).Range("B" & LTrim$(Str$(xRowOut + 1))).Value)

       xRowOut = xRowOut + 2
       m_command = "GSummary '_Ic'"

       MtbProject.ExecuteCommand m_command
       Get_LastGraphImage 1, ThisSheet, "A" & LTrim$(Str$(xRowOut))   
' get Minitab Graph : 1 line of code

       xRowOut = xRowOut + xg_shift

       m_command = "Capa '_Ic' 1; Lspec " & LTrim$(Str$(ic_lsl)) & "; Uspec " & LTrim$(Str$(ic_usl)) & _

       "; Pooled; AMR; UnBiased; OBiased; Toler 6;Overall; CStat."
       MtbProject.ExecuteCommand m_command
       Get_LastGraphImage 1, ThisSheet, "A" & LTrim$(Str$(xRowOut))  ' get Minitab Graph : 1 line of code

       xRowOut = xRowOut + xg_shift

       Application.ScreenUpdating = True
'
 

       Minitab_Says "I have received and processed it, ... " _
       & "The mean value of your Boss Data is " & Format(ic_mtb_mean, "###0.000") & " , while the " _
       & "standard deviation is " & Format(ic_mtb_StDev, "###0.000") & " ... " _
       & "Excel, do you like my analyses and graphs ?? "
      

       Excel_Says "Yes, yes, ... < excellent work >, ... but all this situation is Normal ??"
      

       Minitab_Says "Ask Mr. Anderson or Mr. Darling or send me < my NormTest Command >"
 

       Excel_Says "Ok, I am sending ... NormTest '_Ic'"
 

       m_command= "NormTest '_Ic'"
       MtbProject.ExecuteCommand m_command
       Get_LastGraphImage 1, ThisSheet, "A" & LTrim$(Str$(xRowOut))  
' get Minitab Graph : 1 line of code       

       xRowOut = xRowOut + xg_shift
       Application.ScreenUpdating = True
End Sub

Sub Chat_End()
       Minitab_Says "Excel ... we have a lot of work to do together, in the near future ! " _
       & " It is very easy with the help of M T Bridge Engine!"

 
       frmLetsPlayTogether.Show ' show Maria Pia's Image
 

       MTBridge_Says "Thank you for your attention, ... see you soon to the next meeting ..."
End Sub

'*****************************************************************

'used VBA subs

'*****************************************************************
Sub xmCreate() 
     If IsObject(MtbApp) Then
          If m_me Then
          Else
              x_me = Application.hwnd
              m_me = XMtbObject(x_me, MtbApp) 
 ' Available MTBEngine Functions
              If m_me Then InitMe MtbApp, Application
          End If
     End If
End Sub

 

Sub Excel_Says(byval speechString As String)
        MtbUI.OutputWindow.WriteText ("Xls < " & speechString & " >")   ' write to Minitab Session
        WIN_SPEECH speechString, "Excel ©"  ' Available MTBEngine Functions
        WaitSeconds 2
        DoEvents
End Sub

Sub Excel_Thinks(byval speechString As String)
       With Sheets(ThisSheet)
           .Range("A" & LTrim$(Str$(xRowOut))).FormulaR1C1 = "Xls"      ' write to Excel Sheet
           .Range("B" & LTrim$(Str$(xRowOut))).FormulaR1C1 = speechString
       End With
       WIN_SPEECH speechString, "Excel ©" ' Available MTBEngine Functions
       WaitSeconds 2
       DoEvents
       xRowOut = xRowOut + 1 ' incr Excel output row counter
End Sub


Sub Minitab_Says(byval speechString As String)
       With Sheets(ThisSheet)
           .Range("A" & LTrim$(Str$(xRowOut))).FormulaR1C1 = "Mtb"
           .Range("B" & LTrim$(Str$(xRowOut))).FormulaR1C1 = speechString
        End With
        WIN_SPEECH speechString, "Minitab ©" ' Available MTBEngine Functions
        WaitSeconds 2
        DoEvents
        xRowOut = xRowOut + 1  ' incr Excel output row counter
End Sub


Sub MTBridge_Says(byval speechString As String)
       Dim Title As String
       Title = "MTBridge Engine ©"
       MtbUI.OutputWindow.WriteText (Title & " < " & speechString & " >")    ' write to Minitab Session
       With Sheets(ThisSheet)
           .Range("A" & LTrim$(Str$(xRowOut))).FormulaR1C1 = Title            ' write to Excel Sheet
           .Range("B" & LTrim$(Str$(xRowOut))).FormulaR1C1 = speechString
       End With
       WIN_SPEECH speechString, "MTBridge Engine ©" ' Available MTBEngine Functions
       WaitSeconds 2
       DoEvents
       xRowOut = xRowOut + 1  ' incr Excel output row counter
End Sub
 

 

 

Enhanced Macros Command

Run a Excel Macro using a traditional Minitab macro 

 

        This video shows how to run the previous VBA code from your Minitab session window.

 

 

 

Building a Chat between Crystal Ball , Excel and Minitab step by step

Full Code

 

Attribute VB_Name = "Module_1"   

'*****************************************************  
' File : MTBridge Engine vba Example - 2.5 version
' Author: (c) Franco Anzani
' Copyright : SixSigmaIn Team http://www.sixsigmain.it

'******************************************************
'
'******************************************************
Option Explicit


Declare Function XMtbObject Lib "m_Engine.dll" (ByVal hwnd As Long, ByRef mobj As Object) As Long
Declare Sub WIN_SPEECH Lib "m_Engine.dll" (sVoice As String, sTitle As String)
Declare Sub TILE2VERTICAL Lib "m_Engine.dll" (ByVal hwnd As Long)

Declare Sub WINTOTOP Lib "m_Engine.dll" (ByVal hwnd As Long)
'************************************************************************************
Dim x_me As Long
Dim m_me As Long
Dim MtbApp As Mtb.Application
Dim MtbProject As Mtb.Project
Dim MtbSheet As Mtb.Worksheet

 

Const ModelSheet = "Model"
'************************************************************************************
Sub CB_NewSimulation()
Dim i As Long, CBTrial As Long, n_Fore As Long
Dim xSourceSheet As String, xSourceRange As String, xCol As String, xname As String
Dim dlimit As Double
Dim sLimits(2) As String
Dim m_command As String
Dim speechString As String, stitle As String
Dim xRowOut As Long: xRowOut = 2


          If x_me Then Else xmCreate ' initialize Minitab and Excel in MTBEngine Common Shared Memory
          Set MtbProject = MtbApp.ActiveProject:
          MtbProject.ExecuteCommand "New."
          DoEvents
          Set MtbSheet = MtbApp.ActiveProject.ActiveWorksheet

          TILE2VERTICAL x_me ' set this job as two vertical windows
          With Sheets(ModelSheet)
              .Range("I21:J53").ClearContents
               CBTrial = .Range("D21").Value
              dlimit = .Range("H18").Value
              sLimits(1) = "Lspec " & LTrim$(Str$(dlimit)) '"Lspec 16.5"
              dlimit = .Range("I17").Value
              sLimits(2) = "Uspec " & LTrim$(Str$(dlimit)) '"Uspec 0"
          End With
          If CBTrial < 1000 Then Exit Sub

         speechString = "Hi, Minitab, Excel and Crystal Ball, .... " _
                                & "I am ready to do this simulation and to exchange " & Str$(CBTrial) & " rows data and graphs between you ."

         WIN_SPEECH speechString, "MTBridge Engine ©" ' Available MTBEngine Functions
         DoEvents

         CB.ResetND
         CB.ClearDataND
         CB.Simulation CBTrial
         If CB.CheckDataND Then Exit Sub

         n_Fore = Get_N_O: If n_Fore = 0 Then Exit Sub
         CB.ExtractDataND cbExtChooseAsm, cbChaAll
         CB.ExtractDataND cbExtChooseFore, cbChfAll
         CB.ExtractDataND cbExtExistingSheet, True
         CB.ExtractDataND cbExtOK

          xSourceSheet = ActiveSheet.Name
          MtbSheet.Name = "XSheet_" & LTrim$(Str$(CBTrial)) & "_" & xSourceSheet
          For i = 1 To n_Fore
                xCol = LongTo_xColString(i + 1)
                xname = Range(xCol & "1").Value
                xSourceRange = xCol & "2:" & xCol & LTrim$(Str$(CBTrial + 1))
                mFastPut_NewCol xSourceRange, xSourceSheet, xname
               

                stitle = "'" & xname & " Source Data: CB Sim " & Str$(CBTrial) & " Trials'"
                m_command = "Capa '" & xname & "' 1;" & sLimits(i) & ";Pooled;AMR;UnBiased;OBiased;Toler 6;Overall;Title " & stitle & ";ZBench."
                MtbProject.ExecuteCommand m_command
               Get_LastGraphImage 1, xSourceSheet, "A" & LTrim$(Str$(xRowOut))
               DoEvents
              xRowOut = xRowOut + 23
         Next
End Sub
 

'*****************************************************************

'used VBA subs

'*****************************************************************
Sub xmCreate() 
     If IsObject(MtbApp) Then
          If m_me Then
          Else
              x_me = Application.hwnd
              m_me = XMtbObject(x_me, MtbApp)   ' Available MTBEngine Functions
              If m_me Then InitMe MtbApp, Application
          End If
     End If
End Sub

 

Function Get_N_O() As Long
     Dim s As String
     Dim t As Long
     s = CB.EnumFore
     While s <> ""
           t = t + 1
           s = CB.EnumFore
     Wend
     Get_N_O = t
End Function

 

 

Building a Chat between Crystal Ball , Excel and Minitab step by step

Excel 2007 and 500.000 trials

 

        This video shows the previous VBA code running on Excel 2007 with 1/2 millions of trials. ( 5 minutes video)

 

 

 

MTBridge Engine © - Copyright © Franco Anzani - Patent pending - SixSigmaIn Team snc

All trademarks are the property of their respective owners.