Running VBA macro from Toolbar button

Discussion in 'AutoCAD' started by Joe Sutphin, Jun 29, 2004.

  1. Joe Sutphin

    Joe Sutphin Guest

    I need to run a VBA macro in the ThisDrawing module from a toolbar button
    I'm adding programmatically to an existing toolbar, but I can't seem to get
    the syntax quite right.

    Since I don't do this sort of thing with any kind of regularity, I'm hoping
    someone will be much more versed at how this is done then I seem to be at
    the moment. TIA.

    Joe
    --
     
    Joe Sutphin, Jun 29, 2004
    #1
  2. Joe Sutphin

    Jaime Guest

    This is what i use.

    (vl-vbarun (strcat (findfile "rotate copy.dvb") "!module1.start"))
     
    Jaime, Jun 29, 2004
    #2
  3. Joe Sutphin

    Kevin Terry Guest

    Joe,
    Are you looking for the toolbar code or running macro code? Here's the macro
    stuff I use, if it's the toolbar you're looking for I have that too but it's
    a little more complex.

    One bug I've never taken the time to work out is what happens when you have
    two or more open files with the same macro in their ThisDrawing module, but
    other than that this works. If you fix that little glitch please share :)

    'in the dvb loaded thru start up suite:
    Public Sub Fold_Unit()

    On Error Resume Next

    Const sMacro As String = "FoldingDriver"

    RunMacro "ThisDrawing." & sMacro

    If Err.Number <> 0 Then
    Debug.Print Err.Number & " " & Err.Description
    MsgBox "Could not fold unit.", vbCritical + vbOKOnly
    Err.Clear
    End If

    On Error GoTo 0

    End Sub


    'in the ThisDrawing module of an open file:
    Public Sub FoldingDriver()
    ....

    HTH,
    Kevin
     
    Kevin Terry, Jun 30, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.