Hide Table of Contents
RunMacro2 Method (ISldWorks)

Runs a macro from a project file.

.NET Syntax

Visual Basic (Declaration) 
Function RunMacro2( _
   ByVal FilePathName As System.String, _
   ByVal ModuleName As System.String, _
   ByVal ProcedureName As System.String, _
   ByVal Options As System.Integer, _
   ByRef Error As System.Integer _
) As System.Boolean
Visual Basic (Usage) 
Dim instance As ISldWorks
Dim FilePathName As System.String
Dim ModuleName As System.String
Dim ProcedureName As System.String
Dim Options As System.Integer
Dim Error As System.Integer
Dim value As System.Boolean
 
value = instance.RunMacro2(FilePathName, ModuleName, ProcedureName, Options, Error)
C# 
System.bool RunMacro2( 
   System.string FilePathName,
   System.string ModuleName,
   System.string ProcedureName,
   System.int Options,
   out System.int Error
)
C++/CLI 
System.bool RunMacro2( 
&   System.String^ FilePathName,
&   System.String^ ModuleName,
&   System.String^ ProcedureName,
&   System.int Options,
&   [Out] System.int Error
) 

Parameters

FilePathName
Path and filename of the project file containing the macro
ModuleName
Name of the module in the macro
ProcedureName
Name of the procedure in the module
Options
Option as defined swRunMacroOption_e (supports VBA macros only)
Error
Error as defined by swRunMacroError_e (supports VBA macros only)

Return Value

True if macro runs, false if not

Example

Visual Basic for Applications (VBA)

  1. Create two VBA macros using the following code samples.
  2. Store RunMacroSub.swp in c:\test
  3. Run RunMacro.swp.

'----------------------------
' RunMacro.swp
'---------------------------

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim boolstatus As Boolean

Sub main()
  
Set swApp = Application.SldWorks
   Dim runMacroError As Long
   boolstatus = swApp.RunMacro2("c:\test\RunMacroSub.swp", "RunMacroSub1", "main",   swRunMacroUnloadAfterRun, runMacroError)
End Sub

'---------------------------------------
' RunMacroSub.swp
'---------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks

Sub alternate()
   Set swApp = Application.SldWorks
   swApp.SendMsgToUser "RunMacroSub1:alternate() called."
End Sub

Sub main()
   Set swApp = Application.SldWorks
   swApp.SendMsgToUser "RunMacroSub1:main() called."

End Sub


Running a C# DLL from VBA

boolstatus = Me.swApp.RunMacro2('C:\Test\CSharpMacro\SwMacro\bin\Release\CSharpMacro.dll',

 '', 'Main',  swRunMacroOption_e.swRunMacroDefault, runMacroError)

Remarks

If you specify swRunMacroUnloadAfterRun for Options, then the macro is unloaded from the VBA IDE after running.

Use the path and filename of the compiled DLL for the FilePathName argument for a .NET macro. By default, the procedure is called Main in a C# macro. Because C# is case sensitive, you must specify Main for ProcedureName in this method.. See Running a C# DLL from VBA in the Example section.

Running a macro from an add-in application, standalone .exe, or VBA macro is supported. Running a .NET macro from a .NET macro is also supported, but only if both .NET macros were created using the same VSTA version.

 

See SOLIDWORKS Macros for details.

 

See Also

Availability

SOLIDWORKS 2009 FCS, Revision Number 17.0


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   RunMacro2 Method (ISldWorks)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2019 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.