+ Reply to Thread
Results 1 to 3 of 3

How To execute a button (click event) with code?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-14-2006
    Posts
    75

    Lightbulb How To execute a button (click event) with code?

    Hi all my question is simple i have a Sheet Named GENERAL
    in this sheet i have a button named INIT
    also have 8 sheets more, named: Sheet1, ... Sheet8 in each Sheet i have a button(with a macro(CodeVBA)).

    My question is in the Sheet GENERAL in button INIT how to execute the Click event of Each Button in each Sheet?

    Thanks

  2. #2
    Registered User
    Join Date
    02-14-2006
    Posts
    75

    Re: How To execute a button (click event) with code?

    i try:
      For i = 1 To Sheets.Count
        If Not (Sheets(i).Name = "General" Or Sheets(i).Name = "Telefonos") Then
          Worksheets("General").Cells(k, 3) = Sheets(i).Name 'Renglon/Columna
          Worksheets("General").Cells(k, 4) = Sheets(i).Cells(2, 3)
          Sheets(i).Ejecutar_Click
          k = k + 1
        End If
      Next i
    'In this line i get an error:
    Sheets(i).Ejecutar_Click
    Last edited by Leith Ross; 10-23-2014 at 09:19 PM. Reason: Added Code Tags

  3. #3
    Registered User
    Join Date
    02-14-2006
    Posts
    75

    Re: How To execute a button (click event) with code?

    Show me that some sheets havent buttons but, YES have 1 button how to check?

    Telefonos has 0 buttons:
    
    General has 3 buttons:
    	Button 1	 Attached macro = 'TELEFONOS DE PAGADORAS2.xlsm'!Botón1_Haga_clic_en
    	Button 2	 Attached macro = 'TELEFONOS DE PAGADORAS2.xlsm'!Botón2_Haga_clic_en
    	Button 3	 Attached macro = 'TELEFONOS DE PAGADORAS2.xlsm'!Botón3_Haga_clic_en
    
    Rosario has 0 buttons:
    	
    Macetas has 0 buttons:
    
    El Pino has 0 buttons:
    
    La Finca has 0 buttons:
    
    San Juanito has 0 buttons:
    
    Chinacate has 0 buttons:
    
    Tres Lagunas has 0 buttons:
    
    Santa Rita has 0 buttons:
    
    Huertas Locales has 0 buttons:
    
    Los Patos has 0 buttons:
    
    Cienega Barraganes has 0 buttons:
    
    La Aurora has 0 buttons:
    i checked and need pass the Sheet name as parameter because the button on each Sheet have this VBA code:

    Private Sub Ejecutar_Click()
    Dim i As Integer
    Limpiar
    i = 0
    k = 1
    j = 1
    NumMesas = ActiveSheet.Cells(2, 3) 'Reng,Col
    RangoMinimo = ActiveSheet.Cells(3, 3)
    RangoMaximo = ActiveSheet.Cells(4, 3)
    Diferencia = RangoMaximo - RangoMinimo + 150
    Do While i < NumMesas
        j = j + 1
        Randomize
        RandomNumber = Int((RangoMaximo - RangoMinimo + 1) * Rnd) + 6
        If (RandomNumber >= RangoMinimo And RandomNumber <= RangoMaximo) Then
          If Worksheets("Telefonos").Cells(RandomNumber, 6) <> "X" Then
            ActiveSheet.Cells(k + 1, 6) = Worksheets("Telefonos").Cells(RandomNumber, 2)
            Worksheets("Telefonos").Cells(RandomNumber, 6) = "X"
            k = k + 1
            i = i + 1
          End If
        End If
        If j > Diferencia Then
          Exit Do
        End If
    
    Loop
    End Sub
    then i need in this VBA code:


      k = 2
      For i = 1 To Sheets.Count
        If Not (Sheets(i).Name = "General" Or Sheets(i).Name = "Telefonos" Or Sheets(i).Name = "Resumen") Then
          Worksheets("General").Cells(k, 3) = Sheets(i).Name 'Renglon/Columna
          Worksheets("General").Cells(k, 4) = Sheets(i).Cells(2, 3)
          With Sheets(i)
            Run .Buttons("Ejecutar").OnAction
          End With
          k = k + 1
        End If
      Next i
    Run .Buttons("Ejecutar").OnAction

    i need pass the Sheet name because, i use ActiveSheet.

    see this image: View image: excel1

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Click v double click event code
    By Greg J in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2014, 04:08 AM
  2. Call button click event from a button on anther sheet
    By ajaykgarg in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-25-2010, 09:27 AM
  3. Add Code To Button Click Event Using VBA
    By chergh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2009, 06:24 AM
  4. Execute code from the Worksheet_Change event
    By aldredd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2008, 05:52 AM
  5. Execute code after printing with the BeforePrint event
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2005, 02:05 AM

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