0

I want to automate GageR&R study in minitab.

I found code but the line mtbProject.Commands.Item(1).Outputs.Item(1).Graph.SaveAs.

Gives

Run time error:"IOutput: IOutput collection is empty and contains no valid output object"

enter image description here

Sub msa_macro()
    '
    ' msa_macro Macro
    '
    '
    Dim MtbApp As Mtb.Application
    Dim mtbProject As Mtb.Project
    Dim mtbWorksheet As Mtb.Worksheet
    
    Set MtbApp = New Mtb.Application
    Set mtbProject = MtbApp.ActiveProject
    Set mtbWorksheet = mtbProject.ActiveWorksheet
    
    MtbApp.UserInterface.Visible = True
    MtbApp.UserInterface.DisplayAlerts = True
    
    mtbProject.ExecuteCommand "Execute 'C:\Amir\DataAnalysis2\MSA_FixtureMill_STC049\MSA_STC049_BSM\Results_Files\readfileMinitab_test.mtb' 1."
    
    mtbProject.Commands.Item(1).Outputs.Item(1).Graph.SaveAs "C:\Result_Files\grph1.png", True, GFJPEG  
    
End Sub
Community
  • 1
  • 1

2 Answers2

1

The problem is, that you want to save the Outputs.Item(1) from Commands.Item(1). So you address the first command that you called, which is "Excecute … ", and this has no Output-Item. Therefore the IOutputs Collection for this Command-Item is empty.

The Output-Collection is defined as the Items of Outputs for each command. What you would want to do, is to save the first Output-Item of the command with which you created the graph.

It would be very helpful, if you could provide some information about your readfileMinitab_test.mtb. What are you doing in this .mtb file, is it also a macro-enabled file? I would guess, that you create the graph in this file?

If you want to save your graph as a .png, I guess you might need the MtbGraphFiletype GFPNGColor instead of GFJPEG. You also don´t need to save the file as grph1.png (just grph1 will suffice), as this is done automatically, because you tell Minitab to save it in a specific filetype.

You could also use the digit-code for the Filetypes (which is a little bit shorter). This would mean GFPNGColor = 3 and GFJPEG = 1. For some further information about this I recommend you the Minitab-Automation-Guide.

An example code could look as following:

'This is the first Command Minitab is executing
mtbProject.ExectueCommand "Execute <something>"

'This is the second Command Minitab is executing
mtbProject.ExecuteCommand "Boxplot C" & CStr(i as Integer)

'We want to Save the Graph, which we created with Command 2. We created one graph with
'this Command, to we only have 1 Output.
mtbProject.Commands.Item(2).Outputs.Item(1).Graph.SaveAs <path as String>, True, 3
Florian
  • 47
  • 10
0

Thanks Florian. Yes you are right, I figured it out that I am trying to read the output of the wrong command.

I wanted to execute a sequence of 'Gage R&R' commands and to save an output graph. It is completed now. Thanks again for the helping answer.