+ Reply to Thread
Results 1 to 9 of 9

Repeat buttons

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-28-2010
    Location
    quebec, canada
    MS-Off Ver
    o365
    Posts
    187

    Repeat buttons

    Hi everyone,

    I've got this piece of VBA that seems to do what i want:

    -------
    Sub CreateFormsButton()
    Dim btn As Button
    Dim rng As Range
    With Worksheets("hdcore1")
    Set rng = .Range("h4")
    Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
    With btn
    .Caption = "Coaching"
    .OnAction = "email sent"
    End With
    End With
    End Sub
    ----------

    It creates a button on the h4 cells with a "fit to cell size", can i modify this code to have this button create not only on h4, but i want this button to be on cell h4 to h1000. So i need to modify this code to do some sort of copy paste on multiple cell.

    If i modify the range to h4;h1000, it will create 1 cell the size of my request, but i need 1000 buttons in 1 code.

    Any help on how to loop or modify a quantity?

    thanks!
    Last edited by xatomicx; 10-29-2010 at 12:11 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: Repeat buttons

    You could do something like this:

    Sub CreateMultipleFormsButton()
    Dim btn As Button
    Dim rng As Range
    With Worksheets("hdcore1")
    For i = 1 To 1000
        Set rng = .Range("h" & i)
        Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
        With btn
            .Caption = "Coaching "
            .OnAction = "email sent"
        End With
    Next 'i
    End With
    End Sub
    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    10-28-2010
    Location
    quebec, canada
    MS-Off Ver
    o365
    Posts
    187

    Re: Repeat buttons

    great idea! thank you very much,

    But i get a VB error 400 when i apply the code, i can't find out why, anyone knows what doesnt work in this code? can't pinpoint it

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Repeat buttons

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Repeat buttons

    Add the code tags before I lock the post

  6. #6
    Forum Contributor
    Join Date
    10-28-2010
    Location
    quebec, canada
    MS-Off Ver
    o365
    Posts
    187

    Re: Repeat buttons

    here we go

    Sorry!

  7. #7
    Forum Contributor
    Join Date
    10-28-2010
    Location
    quebec, canada
    MS-Off Ver
    o365
    Posts
    187

    Re: Repeat buttons

    i've found something,

    This code works

    Sub CreateMultipleFormsButton()
    Dim btn As Button
    Dim rng As Range
    With Worksheets("hdcore1")
    For i = 4 To 1000
        Set rng = .Range("h" & i)
        Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
        With btn
            .Caption = "Coaching "
        End With
    Next i
    End With
    End Sub

    i remove the onaction, but now i can't click on it to make it change from coaching, to email sent, anyone can help reintegrate the onaction so it change name when i click on it?
    Last edited by xatomicx; 10-29-2010 at 01:08 PM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: Repeat buttons

    .OnAction determines the *macro* that is run when the button is clicked. Of of the things that macro could do is to change the caption.

    I rather assumed that you had the rest of the code to go with the button you've(s) created.

    The error comes from the fact that you have/had a space in the text.

    Change it to: .OnAction = "eMailSent"

    But, as stated above, you need a macro called "eMailSent" to send the email (?) and change the caption.

    Regards

  9. #9
    Forum Contributor
    Join Date
    10-28-2010
    Location
    quebec, canada
    MS-Off Ver
    o365
    Posts
    187

    Re: Repeat buttons

    Thanks TMSchucks!

    The macro for email sent is not created yet no,

    I'll first figure out how i want my buttons to be displayed, and i'll give a shot at doing the macro for email, i've found pretty clear tutorial on how to do so,

    I will get back with a post here if i'm lost

    Thank you!

+ 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