Home Image-Pro Automation (Macros, Apps, Reports)

Macro do not start more than 1 time

Hi,

I did a macro for an automation of image analysis.

The user can start my macro through a form. In a dropdown the user select which macro to run, and then, press "Run".

Here's the code of the Run button 

Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click Dim strMacro As String m_RunMacro = New SimpleScript Select Case ddlRoutine.Text Case "AnalyseImage_03-5" strMacro = "AnalyseImage_0305" Case Else Exit Sub End Select With Automate.ScriptingCommands.PlayMacro(m_RunMacro) .MacroFile = "AnalyseImage>Macros.vb" .MacroName = strMacro .Run(Nothing) End With End Sub My problem is that the macro won't run more than 1 time. 1- I show the form 2- I select a macro to run in dropdown 3- I press run *the macro run perfectly 4- I press run again to run the same macro a second time *the macro won't start 5- I press run again to run the same macro a second time *the macro won't start etc. etc. If I debug the code, the handles of my click button is executed...but the .Run of the macro do not work. Thanks in advance. Martin

Answers

  • Hi Martin,

    There could be something wrong with your global variables or something else.
    You can skip defining SimpleScript variable. Please use the macro below as example:

    Public Module Module1
    
        Public Sub CallMyMacro
            Dim strMacro As String = "SayHi"
            With Automate.ScriptingCommands.PlayMacro(Nothing)
                .MacroFile = "Project4>Module1.vb"'modify project name!
                .MacroName = strMacro
                .Run(Nothing)
            End With
        End Sub
    
        Public Sub SayHi
            MsgBox("Hi")
        End Sub
    
    End Module
    

    Regards,

    Yuri
  • Yuri,

    I get the same problem.

    I tried to put the call within a try catch...to check if there is an error...but no error.

        Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
            Dim strMacro As String
    
            Select Case ddlRoutine.Text
                Case "AnalyseImage_03-5"
                    strMacro = "AnalyseImage_0305"
                Case Else
                    Exit Sub
            End Select
    
            Try
                With Automate.ScriptingCommands.PlayMacro(Nothing)
                    .MacroFile = "AnalyseImage>Macros.vb"
                    .MacroName = strMacro
                    .Run(Nothing)
                End With
            Catch ex As Exception
    
            Finally
            End Try
        End Sub
    
    Can this be related to my form ?
    I'm calling Public sub or my file Macros.vb from my Form. All those files are within the same project.
    
    Any other idea ?
    
    thanks,
    
    
  • Hi Martin,

    The easiest would be to call the macro directly:
    AnalyseImage_0305()
    If it's not possible, could you upload your project? Then we can make sure it does the right thing.

    Pierre
  • Ohh !
    Pierre, thanks a lot !

    I didn't thought I can call directly my routine.

    Thanks !
Sign In or Register to comment.