how to add toolbar icon by VB or VBA

Discussion in 'AutoCAD' started by Soe, Jul 14, 2003.

  1. Soe

    Soe Guest

    when i tried to add in toolbar icon by VBA or VB, i can see new toolbar
    icon, however, after close the application and reopen it, the toolbar icon
    is no more there.
    when i use right click and add userdefined button, it works.
    any suggestion how to keep toolbar icon?
     
    Soe, Jul 14, 2003
    #1
  2. Soe

    LHGO Guest

    Sub VbaMenu()

    Dim currMenuGroup As AcadMenuGroup
    Dim newToolBar As AcadToolbar
    Dim newToolBarButton As AcadToolbarItem
    Dim openMacro As String
    Dim SmallBitmapName As String
    Dim LargeBitmapName As String

    On Error GoTo Err_Control

    'Load the VBAMENU menu
    ThisDrawing.Application.MenuGroups.Load "VbaMenu.mns"

    'We now need to obtain a reference to our new menu, VBAMENU
    'Use MenuGroups property to obtain reference to main VBAMENU menu
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("VBAMENU")

    '==========================================================
    ' Create Toolbar Menu
    Set newToolBar = currMenuGroup.Toolbars.Add("Vba Menu")
    '==========================================================
    'vbaload macro and bitmaps
    openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaload" & Chr(32)
    Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1,
    "VBA Load", "VBALoad", openMacro, False)
    SmallBitmapName = "VBALOAD.BMP"
    LargeBitmapName = "VBALOAD.BMP"
    newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
    newToolBarButton.HelpString = "Load a VBA Application"
    '==========================================================
    'vbaide macro and bitmaps
    openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaide" & Chr(32)
    Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1,
    "VBA Editor", "VBA Editer", openMacro, False)
    SmallBitmapName = "VBAIDE.BMP"
    LargeBitmapName = "VBAIDE.BMP"
    newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
    '==========================================================
    'vbaide macro and bitmaps
    openMacro = Chr(3) & Chr(3) & Chr(95) & "vbarun" & Chr(32)
    Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1,
    "Run Macro", "Run Macro", openMacro, False)
    SmallBitmapName = "VBAMACRO.BMP"
    LargeBitmapName = "VBAMACRO.BMP"
    newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
    '==========================================================
    'vbaide macro and bitmaps
    openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaman" & Chr(32)
    Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1,
    "VBA Manager", "VBA Manager", openMacro, False)
    SmallBitmapName = "VBAMAN.BMP"
    LargeBitmapName = "VBAMAN.BMP"
    newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
    '==========================================================

    're-compile the VBAMENU menu - VBAMENU.MNC
    currMenuGroup.Save acMenuFileCompiled

    'Un-comment the next line to save it as a MNS file.
    currMenuGroup.Save acMenuFileSource

    Just_Here:
    Exit Sub

    Err_Control:
    Select Case Err.Number
    'The menu exists, just exit
    Case -2147024809
    Err.Clear
    Resume Just_Here
    Case Else
    MsgBox Err.Description
    Exit Sub
    End Select
    End Sub
     
    LHGO, Jul 14, 2003
    #2
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.