See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: New to VBA-Problems With Buttons etc.

  1. #1
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Unhappy New to VBA-Problems With Buttons etc.

    Hi to everyone,
    my name is Vaggelis and i am trying to learn vba. I have a good book with examples and theory but when i tried to associate the macro and the button i had no luck!
    The example says:
    AddLayer (ok, i wrote the code)
    I create a button in AutoCAD and the major problem is what to write in Macro.

    Can pls anyone explain to me the procedure?

    Thanks!!!

  2. #2
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    Sorry my friends,
    i just found the solution:

    Run a VBA Macro from a Toolbar or Menu

    You can run a VBA macro from an AutoCAD toolbar or menu by simply changing the Macro property for that toolbar or menu. The Macro property must be set equal to

    -VBARUN filename.dvb!modulename.macroname

    where filename is the name of the project file, modulename is the name of the module containing the macro to be run, and macroname is the name of the macro. The file name is only required when the file is not loaded in the current session of AutoCAD. If the file name is provided, the file will be loaded.

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    That works. You can also define a lisp wrapper which allows you to repeat the command by hitting enter. See the sticky thread at the top of this forum. Then the button macro is simply the command name.
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    Sorry my friends but I am doing something wrong and I can't work.
    Although my button has the command vbarun.... it doesn't work.
    When I press it I get the following message:
    Command: -VBARUN
    Macro name: Project2.dvb!Module1.AddLayer
    Macro not found.

    Any suggestions?

    Thanks

  5. #5
    Active Member
    Join Date
    2007-12
    Posts
    68
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    Tough to determine without seeing the code.... check the backslashes in your pathname .... check to make sure the actual filename, module name, and routine name are correct ...

  6. #6
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    OK the code is an example because now I am learning:

    Public Sub AddLayer()
    Dim strLayerName As String
    Dim objLayer As AcadLayer
    strLayerName = InputBox("Name of Layer to add: ")
    If "" = strLayerName Then Exit Sub ' exit if no name entered
    On Error Resume Next ' handle exceptions inline
    'check to see if layer already exists
    Set objLayer = ThisDrawing.Layers(strLayerName)
    If objLayer Is Nothing Then
    Set objLayer = ThisDrawing.Layers.Add(strLayerName)
    If objLayer Is Nothing Then ' check if obj has been set
    MsgBox "Unable to Add '" & strLayerName & "'"
    Else
    MsgBox "Added Layer '" & objLayer.Name & "'"
    End If
    Else
    MsgBox "Layer already existed"
    End If
    End Sub


    To the button Macro :

    -VBARUN Project1.dvb!Module1.AddLayer

    I use the Load Project command but it still returns the same message for the macro.

    Yesterday everything was right but today no.

  7. #7
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    If your project isn't stored in a folder which is defined in the support file search path, then your button macro needs to specify the full file path to the dvb.
    C:> ED WORKING....


    LinkedIn

  8. #8
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Smile Re: New to VBA-Problems With Buttons etc.

    Thanks Ed!
    That is the solution.

    Another question: I have code in a module and asks for a point (pick point), length and witdh. Now I am trying to create a form with one button for the point and two text boxes for length and width. I can't understand how I can assign to each element the specific task.
    Where I can find informations about ?

    Thanks!

  9. #9
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    1

    Default Re: New to VBA-Problems With Buttons etc.

    With Object Oriented Programming, OOP, you assign the behavior to each object. If you want the button to do something when you click it, you write code for the button's click event. In the project browser, select the form, and click on the "View Code" button. In the upper left of the form's code module is the object list. Select the point button and it will create a method signature for the button's default method, which is the OnClick method. Now add your code to the OnClick method.

    In the list at the upper right, you can select other methods supported by the current control.
    C:> ED WORKING....


    LinkedIn

  10. #10
    Member vaggelis.1109's Avatar
    Join Date
    2005-11
    Location
    Athens-Greece
    Posts
    27
    Login to Give a bone
    0

    Default Re: New to VBA-Problems With Buttons etc.

    Ok.I created the form, I assigned specific code at each button but I don't know how I call the form from autocad envornment. I asked about a macro at the first post but I don't know what to do in order to push a toolbar button and see form. I have one button in my toolbar waiting but what is the ''order'' to understand the cooperation with form?
    In the module ''way'' I wrote :

    The Macro property must be set equal to

    -VBARUN filename.dvb!modulename.macroname

    Now each element in the form has a part of that code and I can't understand what to write in Macro property. I don't know a lot about VBA but want to have a logic like array command (example..).

    Thanks again for your time and info.

Page 1 of 2 12 LastLast

Similar Threads

  1. Losing my buttons
    By csorensen in forum CAD Management - General
    Replies: 1
    Last Post: 2010-08-31, 03:44 PM
  2. Tablet buttons
    By Coolmo in forum AutoCAD CUI Menus
    Replies: 1
    Last Post: 2005-09-23, 03:15 PM
  3. Display buttons
    By pgastelum77763 in forum AutoCAD General
    Replies: 1
    Last Post: 2005-08-02, 09:23 PM
  4. buttons on digitzers
    By ldavis.23383 in forum AutoCAD CUI Menus
    Replies: 1
    Last Post: 2005-06-08, 08:54 PM
  5. Status Bar Buttons
    By ntaylor in forum API Wish List
    Replies: 5
    Last Post: 2005-03-02, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •