Home > Back-end >  Solidworks macro button - method dropdown is empty
Solidworks macro button - method dropdown is empty

Time:10-11

I've made two macros in SolidWorks VBA (one to save PDF files and one to save DXF files), and I want to share some common code. This should be easy, by calling subprocedures from the other modules (e.g. call module.sub()).

I have two modules (one for PDFs and one for DXFs), and one "shared" module that the other two call.

Here's some of my PDF-saving code, in the "pdf" module. The "dxf" module is the same except it calls shared_module.shared_sub("dxf") instead of shared_module.shared_sub("pdf").

Sub save_pdf()
    ' Calls the shared module to save a PDF file this time
    call shared_module.shared_sub("pdf")    
End Sub

Here's some of my "shared_module" code:

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2


Sub shared_sub(byval file_extension as String)

    ' get the solidworks application object
    Set swApp = Application.SldWorks
    
    ' get the current opened document object
    Set swModel = swApp.ActiveDoc

    ' do some shared stuff here, with the "file_extension" string
    ...

End Sub

My problem is, when I create or edit the macro button, the "Method:" dropdown menu is empty... Any ideas why?

If I have just one macro/module/main() subroutine, it shows up. But when I add other modules, it's blank.

I checked showing method dropdown is empty

CodePudding user response:

I've solved the problem, simply by putting all my subs into the same module. It seems if there's more than one module, the "create macro button" dropdown doesn't know where to look for the "methods"...

No big deal to have them all in one module, instead of having separate modules.

  • Related