E
erco
Guest
bonjour à tous,
j'ai créé un code qui permet d'insérer dans une nouvelle feuille 3 boutons (permettant, en cliquant dessus, de revenir sur des feuilles déterminées).
voilà les codes :
sub Creation
ActiveWorkbook.Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = c
With Worksheets(c)
Set MyButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With MyButton
.Left = 20
.Top = 20
.Width = 100
.Height = 30
With .Object
.Caption = 'RCC'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
' Création du bouton 'Retour SSJ'
With Worksheets(c)
Set YourButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With YourButton
.Left = 20
.Top = 80
.Width = 100
.Height = 30
With .Object
.Caption = 'SSJ'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
' Création du bouton 'RRR'
With Worksheets(c)
Set HisButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With HisButton
.Left = 20
.Top = 140
.Width = 100
.Height = 30
With .Object
.Caption = 'RRR'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
end sub
j'ai 3 boutons : RCC, SSJ et RRR
VOici les codes de chaque bouton:
Sub WritePrivateSubThisWorBookLastSheet()
' Macro qui écrit le code du bouton 'RCC'
Dim VBA As String
Const WSName As String = 'RCC'
VBA = VBA & 'Private Sub CommandButton1_Click()' & vbCrLf
VBA = VBA & 'Worksheets(''' & WSName & ''').Activate' & vbCrLf
VBA = VBA & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString VBA
End With
End With
End Sub
Sub WritePrivateSubSSJ()
' Macro qui écrit le code du bouton 'Retour Sous-Jacents'
Dim SJ As String
Const WSJacent As String = 'SSJ'
SJ = SJ & 'Private Sub CommandButton2_Click()' & vbCrLf
SJ = SJ & 'Worksheets(''' & WSJacent & ''').Activate' & vbCrLf
SJ = SJ & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString SJ
End With
End With
End Sub
Sub WritePrivateSubRRR()
' Macro qui écrit le code du bouton 'RRR'
Dim Reuters As String
Rtrs = Rtrs & 'Private Sub CommandButton3_Click()' & vbCrLf
Rtrs = Rtrs & 'Call RecupRRR' & vbCrLf
Rtrs = Rtrs & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString Reuters
End With
End With
End Sub
Le 3ème bouton permet d'exécuter la macro 'RecupRRR'
Le 2ème bouton permet de revenir sur la feuille 'SSJ'
Le 1er bouton permet de revenir sur la feuille 'RCC'
je n'ai pas de pb pour éxécuter la macro qui permet de créer les boutons.
je n'ai pas non plus de problème pour éxécuter l'une après l'autre les macros qui écrivent les codes des boutons
Je souhaite en fait exécuter l'une après l'autre ces macros : cad après la création des boutons, l'écriture automatique des codes de ces boutons.
je fais la macro :
Sub Gogo
call Creation
call WritePrivateSubThisWorBookLastSheet
call WritePrivateSubSSJ
call WritePrivateSubRRR
end sub
mais excel plante à chaque fois
j'ai l'impression qu'excel ne peut pas exécuter les 3 dernières macros automatiquement...
pourquoi ?
comment puis-je faire??
merci d'avance
j'ai créé un code qui permet d'insérer dans une nouvelle feuille 3 boutons (permettant, en cliquant dessus, de revenir sur des feuilles déterminées).
voilà les codes :
sub Creation
ActiveWorkbook.Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = c
With Worksheets(c)
Set MyButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With MyButton
.Left = 20
.Top = 20
.Width = 100
.Height = 30
With .Object
.Caption = 'RCC'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
' Création du bouton 'Retour SSJ'
With Worksheets(c)
Set YourButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With YourButton
.Left = 20
.Top = 80
.Width = 100
.Height = 30
With .Object
.Caption = 'SSJ'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
' Création du bouton 'RRR'
With Worksheets(c)
Set HisButton = .OLEObjects.Add(classtype:='Forms.CommandButton.1')
End With
With HisButton
.Left = 20
.Top = 140
.Width = 100
.Height = 30
With .Object
.Caption = 'RRR'
.BackColor = &H8000000F
.ForeColor = &H80000012
With .Font
.Bold = False
.Italic = False
.Size = 10
End With
End With
End With
end sub
j'ai 3 boutons : RCC, SSJ et RRR
VOici les codes de chaque bouton:
Sub WritePrivateSubThisWorBookLastSheet()
' Macro qui écrit le code du bouton 'RCC'
Dim VBA As String
Const WSName As String = 'RCC'
VBA = VBA & 'Private Sub CommandButton1_Click()' & vbCrLf
VBA = VBA & 'Worksheets(''' & WSName & ''').Activate' & vbCrLf
VBA = VBA & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString VBA
End With
End With
End Sub
Sub WritePrivateSubSSJ()
' Macro qui écrit le code du bouton 'Retour Sous-Jacents'
Dim SJ As String
Const WSJacent As String = 'SSJ'
SJ = SJ & 'Private Sub CommandButton2_Click()' & vbCrLf
SJ = SJ & 'Worksheets(''' & WSJacent & ''').Activate' & vbCrLf
SJ = SJ & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString SJ
End With
End With
End Sub
Sub WritePrivateSubRRR()
' Macro qui écrit le code du bouton 'RRR'
Dim Reuters As String
Rtrs = Rtrs & 'Private Sub CommandButton3_Click()' & vbCrLf
Rtrs = Rtrs & 'Call RecupRRR' & vbCrLf
Rtrs = Rtrs & 'End Sub' & vbCrLf
With ThisWorkbook
With .VBProject.VBComponents(.Sheets(.Sheets.Count).CodeName).CodeModule
.AddFromString Reuters
End With
End With
End Sub
Le 3ème bouton permet d'exécuter la macro 'RecupRRR'
Le 2ème bouton permet de revenir sur la feuille 'SSJ'
Le 1er bouton permet de revenir sur la feuille 'RCC'
je n'ai pas de pb pour éxécuter la macro qui permet de créer les boutons.
je n'ai pas non plus de problème pour éxécuter l'une après l'autre les macros qui écrivent les codes des boutons
Je souhaite en fait exécuter l'une après l'autre ces macros : cad après la création des boutons, l'écriture automatique des codes de ces boutons.
je fais la macro :
Sub Gogo
call Creation
call WritePrivateSubThisWorBookLastSheet
call WritePrivateSubSSJ
call WritePrivateSubRRR
end sub
mais excel plante à chaque fois
j'ai l'impression qu'excel ne peut pas exécuter les 3 dernières macros automatiquement...
pourquoi ?
comment puis-je faire??
merci d'avance