+ Reply to Thread
Results 1 to 6 of 6

Calling a Sub from another

  1. #1
    Registered User
    Join Date
    02-02-2006
    Posts
    12

    Calling a Sub from another

    Hello all,

    My code below creates a floating menu called "New Name", but when I click on the menu, nothing happens. I want it to display a message.

    I have written as...

    .
    .
    .
    .OnAction = "newname"
    .


    Sub newgame()
    MsgBox "Enter new name"
    End Sub



    My full code is as follows....

    Option Explicit

    Const ToolBarName As String = "User Options"

    'This code runs whenever the workbook is open
    Sub Workbook_Open()

    Dim returnvalue As Integer

    returnvalue = MsgBox("Welcome !!!" & vbCrLf & "Do you want to start ?", 65, "Greetings")

    If returnvalue = 2 Then
    Application.Quit
    Else
    Call CreateMenubar

    End If

    End Sub

    'This code runs before the workbook is closed
    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    MsgBox "This code ran at Excel close!"
    Call RemoveMenubar

    End Sub


    'This code removes the floating tool bar before closing
    Sub RemoveMenubar()

    On Error Resume Next
    Application.CommandBars(ToolBarName).Delete
    On Error GoTo 0

    End Sub

    'This code creats the floating tool bar
    Sub CreateMenubar()

    Dim iCtr As Long
    Dim temp As Long

    Dim MacNames As Variant
    Dim CapNamess As Variant
    Dim TipText As Variant

    Call RemoveMenubar



    With Application.CommandBars.Add
    .Name = ToolBarName
    .Left = 990
    .Top = 105
    .Protection = msoBarNoProtection
    .Visible = True
    .Position = msoBarFloating
    .Width = 25

    With .Controls.Add(Type:=msoControlButton)
    .BeginGroup = True
    .OnAction = "newname"
    .Caption = "&New Name"
    .Style = msoButtonIconAndCaption
    .FaceId = 71 + 1
    .TooltipText = "Enter new name"
    End With


    End With
    End Sub
    '===========================================
    Sub newname()
    MsgBox "Enter new name"
    End Sub

  2. #2
    Tom Ogilvy
    Guest

    Re: Calling a Sub from another

    have you assigned a macro to the button on the floating menu? (assuming
    it is a custom button and not a built in button)

    --
    Regards,
    Tom Ogilvy

    "shashi1515" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hello all,
    >
    > My code below creates a floating menu called "New Name", but when I
    > click on the menu, nothing happens. I want it to display a message.
    >
    > I have written as...
    >




  3. #3
    Registered User
    Join Date
    02-02-2006
    Posts
    12

    Calling a Sub from another

    Tom,

    The button I created is on a Floating Menu bar. I know how to assign a macro to button created from Forms. but, how should I assign a Macro to a button on floating toolbar. Please help.

    Thanks,
    Shashi

  4. #4
    Tom Ogilvy
    Guest

    Re: Calling a Sub from another

    In code, you use the OnAction property.

    manually, you go to Tools, Customize,
    then go to the control and right click on it and select assign macro.

    --
    Regards,
    Tom Ogilvy


    "shashi1515" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Tom,
    >
    > The button I created is on a Floating Menu bar. I know how to assign a
    > macro to button created from Forms. but, how should I assign a Macro to
    > a button on floating toolbar. Please help.
    >
    > Thanks,
    > Shashi
    >
    >
    > --
    > shashi1515
    > ------------------------------------------------------------------------
    > shashi1515's Profile:

    http://www.excelforum.com/member.php...o&userid=31109
    > View this thread: http://www.excelforum.com/showthread...hreadid=508233
    >




  5. #5
    Registered User
    Join Date
    02-02-2006
    Posts
    12

    Calling a Sub from another

    Thank you. I got it.

    But, when I close the excel and re-open it, I have to assign the macros again. How to make them permanent??? Please advice.

    Thanks,
    Shashi

  6. #6
    Tom Ogilvy
    Guest

    Re: Calling a Sub from another

    I haven't seen such a problem unless you have deleted the menu item in which
    case, when you create it again, you would need to assign a macro.

    --
    Regards,
    Tom Ogilvy

    "shashi1515" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Thank you. I got it.
    >
    > But, when I close the excel and re-open it, I have to assign the macros
    > again. How to make them permanent??? Please advice.
    >
    > Thanks,
    > Shashi
    >
    >
    > --
    > shashi1515
    > ------------------------------------------------------------------------
    > shashi1515's Profile:

    http://www.excelforum.com/member.php...o&userid=31109
    > View this thread: http://www.excelforum.com/showthread...hreadid=508233
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1