AnsweredAssumed Answered

How do I write the code to open a Macro and then fill out the Macro's form?

Question asked by Shawn Tracey on May 24, 2012
Latest reply on May 29, 2012 by Keith Rice

I'm looking for some help.

 

What I am trying to do, is write code (in VBA) that will:

 

1 - Open an Existing Macro from a specific location [SolidWorks: RunMacro2]

2 - Fill out the form that is used to size the components.

 

I have written the code to open the Macro, but when the Macro runs, the form will not open up.  If I run the Macro manually it works fine.  Am I missing something that will allow the Macro Form to open?  I thought I might need to use a GetObject to grab the form and then dump the required info into it, but the form isn't even opening at this point. Here is the code I am using to open the form and attempting to populate the form.  I'm a novice programmer so any help is appreciated.

 

    Dim runMacroError       As Long

    Dim boolstatus          As Boolean

 

boolstatus = swApp.RunMacro2("C:\My Documents\MyMacroName.swp", "Module", "main", swRunMacroDefault, runMacroError)

 

     Dim obj As Object


     For Each obj In Forms!frmMyFormName

        Select Case obj.Name
             Case "txtTextbox1"
                  obj.Value = dblMyVariable1
             Case "txtTextbox2"
                  obj.Value = dblMyVariable2

 

        End Select
    Next

Outcomes