Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    floating command button (97+)

    Using the control toolbox I know how to create a command button which then calls code in its code window---my problem is that command button is not "floatable" and cannot be moved by user if it hides some relevant text which user needs to view---is it possible to "float" the button?? ---I am sure that a floating command button can be vba coded without using the control toolbox and would like to see how its done
    Tia
    Smbs

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: floating command button (97+)

    You could do this, but you would be fighting Excel all the way. Buttons are meant to stay put, but a toolbar is made to float, so you mearly make a single button toolbar. HTH --Sam
    <pre>Private Sub buildReturnBar()
    ' Create a toolbar and button to return
    On Error Resume Next
    Application.CommandBars("Return").Delete
    On Error GoTo 0
    With Application.CommandBars.Add(Name:="Return")
    .Visible = True
    .Top = 200
    .Left = 50
    With .Controls.Add(Type:=msoControlButton, ID:=2950)
    .Caption = "Return to Processing"
    .OnAction = "processingMacro"
    .Style = msoButtonCaption
    End With
    End With
    End Sub</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: floating command button (97+)

    Thanx --works just fine but the limitation of this "as per my understanding' is that fonts/colors/background cannot be changed --they are all system toolbar properties and therefore any changes would be global and affect all toolbars---Is my understanding correct?
    Thanx again
    Smbs

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: floating command button (97+)

    Command buttons have a Top and Left property which can be manipulated. Using the KeyDown event of a coomand button should allow you to do just that. The following example allows you to move a command button around the screen using the cursor keys. However the button needs to have focus first. You can get this work by right clicking on the button and then using the cursor keys. Or you can just left click and before releasing use the cursor keys, and release the mouse keypress when it is not over the button in question.

    Private Sub CommandButton1_KeyDown( _
    ByVal KeyCode As MSForms.ReturnInteger, _
    ByVal Shift As Integer)
    With CommandButton1
    Select Case KeyCode
    Case 37
    .Left = .Left - 25
    Case 38
    .Top = .Top - 10
    Case 39
    .Left = .Left + 25
    Case 40
    .Top = .Top + 10
    End Select
    End With
    End Sub

    You will need to chyange CommandButton1 to whatever name you have applied to your button, and the Left and Top values can be altered to suit.

    Andrew C

Posting Permissions

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