Bonjour,
Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de
toutes les macros contenues dans le classeur courant.
Comment peut-on faire ?
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
LSteph
Bonsoir,
Pour reproduire cet exemple attention de cocher vbextensibility dans références
http://cjoint.com/?jyx4l0j57j
-- 'lSteph
Voici le code:
'''''ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean) Call EffaceCommande End Sub
Private Sub Workbook_Open() Call EffaceCommande Call AjouteCommande End Sub
'''''Userform1 Private Sub UserForm_Initialize() 'attention de cocher vbextensibility dans références Dim oMod As VBComponent, J As Integer Dim myProc As String, wbn As String Application.ScreenUpdating = False On Error Resume Next wbn = ActiveWorkbook.Name On Error GoTo 0 If Len(wbn) = 0 Then MsgBox "Fonctionne sur classeur actif": Unload Me: Exit Sub
Me.ComboBox1.Clear For Each oMod In ActiveWorkbook.VBProject.VBComponents With oMod.CodeModule For J = 1 To .CountOfLines If InStr(1, .Lines(J, 1), "Sub ", 1) > 0 Or _ InStr(1, .Lines(J, 1), "Function ", 1) > 0 And _ InStr(1, .Lines(J, 1), "End ", 1) = 0 Then If InStr(1, .Lines(J, 1), "InStr", 1) = 0 Then Me.ComboBox1.AddItem .Lines(J, 1) End If End If Next J End With Next
End Sub
'''''''''Module1 Sub AjouteCommande() Call EffaceCommande With Application.CommandBars(1).Controls("Outils").Controls.Add(msoControlButton) .Caption = "ListeMacros" .OnAction = "AfficheUf"
End With
End Sub
Sub EffaceCommande() On Error Resume Next Application.CommandBars(1).Controls("Outils").Controls("ListeMacros").Delete End Sub
Sub AfficheUf() UserForm1.Show End Sub ''''''''''''''''''''''''''''
Bonjour, Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de toutes les macros contenues dans le classeur courant. Comment peut-on faire ?
Merci pour vos éclairages
Bonsoir,
Pour reproduire cet exemple attention de cocher vbextensibility dans
références
http://cjoint.com/?jyx4l0j57j
--
'lSteph
Voici le code:
'''''ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call EffaceCommande
End Sub
Private Sub Workbook_Open()
Call EffaceCommande
Call AjouteCommande
End Sub
'''''Userform1
Private Sub UserForm_Initialize()
'attention de cocher vbextensibility dans références
Dim oMod As VBComponent, J As Integer
Dim myProc As String, wbn As String
Application.ScreenUpdating = False
On Error Resume Next
wbn = ActiveWorkbook.Name
On Error GoTo 0
If Len(wbn) = 0 Then MsgBox "Fonctionne sur classeur actif": Unload Me:
Exit Sub
Me.ComboBox1.Clear
For Each oMod In ActiveWorkbook.VBProject.VBComponents
With oMod.CodeModule
For J = 1 To .CountOfLines
If InStr(1, .Lines(J, 1), "Sub ", 1) > 0 Or _
InStr(1, .Lines(J, 1), "Function ", 1) > 0 And _
InStr(1, .Lines(J, 1), "End ", 1) = 0 Then
If InStr(1, .Lines(J, 1), "InStr", 1) = 0 Then
Me.ComboBox1.AddItem .Lines(J, 1)
End If
End If
Next J
End With
Next
End Sub
'''''''''Module1
Sub AjouteCommande()
Call EffaceCommande
With
Application.CommandBars(1).Controls("Outils").Controls.Add(msoControlButton)
.Caption = "ListeMacros"
.OnAction = "AfficheUf"
End With
End Sub
Sub EffaceCommande()
On Error Resume Next
Application.CommandBars(1).Controls("Outils").Controls("ListeMacros").Delete
End Sub
Sub AfficheUf()
UserForm1.Show
End Sub
''''''''''''''''''''''''''''
Bonjour,
Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de
toutes les macros contenues dans le classeur courant.
Comment peut-on faire ?
Pour reproduire cet exemple attention de cocher vbextensibility dans références
http://cjoint.com/?jyx4l0j57j
-- 'lSteph
Voici le code:
'''''ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean) Call EffaceCommande End Sub
Private Sub Workbook_Open() Call EffaceCommande Call AjouteCommande End Sub
'''''Userform1 Private Sub UserForm_Initialize() 'attention de cocher vbextensibility dans références Dim oMod As VBComponent, J As Integer Dim myProc As String, wbn As String Application.ScreenUpdating = False On Error Resume Next wbn = ActiveWorkbook.Name On Error GoTo 0 If Len(wbn) = 0 Then MsgBox "Fonctionne sur classeur actif": Unload Me: Exit Sub
Me.ComboBox1.Clear For Each oMod In ActiveWorkbook.VBProject.VBComponents With oMod.CodeModule For J = 1 To .CountOfLines If InStr(1, .Lines(J, 1), "Sub ", 1) > 0 Or _ InStr(1, .Lines(J, 1), "Function ", 1) > 0 And _ InStr(1, .Lines(J, 1), "End ", 1) = 0 Then If InStr(1, .Lines(J, 1), "InStr", 1) = 0 Then Me.ComboBox1.AddItem .Lines(J, 1) End If End If Next J End With Next
End Sub
'''''''''Module1 Sub AjouteCommande() Call EffaceCommande With Application.CommandBars(1).Controls("Outils").Controls.Add(msoControlButton) .Caption = "ListeMacros" .OnAction = "AfficheUf"
End With
End Sub
Sub EffaceCommande() On Error Resume Next Application.CommandBars(1).Controls("Outils").Controls("ListeMacros").Delete End Sub
Sub AfficheUf() UserForm1.Show End Sub ''''''''''''''''''''''''''''
Bonjour, Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de toutes les macros contenues dans le classeur courant. Comment peut-on faire ?
Merci pour vos éclairages
JB
Bonjour,
Private Sub UserForm_Initialize() For Each c In ActiveWorkbook.VBProject.VBComponents For ligne = 1 To c.CodeModule.CountOfLines temp = Trim(c.CodeModule.Lines(ligne, 1)) If Left(temp, 3) = "Sub" Then Me.ComboBox1.AddItem Mid(Left(temp, Len(temp) - 2), 4) Next Next End Sub
JB
On 24 sep, 20:12, "Herve" wrote:
Bonjour, Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de toutes les macros contenues dans le classeur courant. Comment peut-on faire ?
Merci pour vos éclairages
Bonjour,
Private Sub UserForm_Initialize()
For Each c In ActiveWorkbook.VBProject.VBComponents
For ligne = 1 To c.CodeModule.CountOfLines
temp = Trim(c.CodeModule.Lines(ligne, 1))
If Left(temp, 3) = "Sub" Then Me.ComboBox1.AddItem Mid(Left(temp,
Len(temp) - 2), 4)
Next
Next
End Sub
JB
On 24 sep, 20:12, "Herve" <seba...@free.fr> wrote:
Bonjour,
Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de
toutes les macros contenues dans le classeur courant.
Comment peut-on faire ?
Private Sub UserForm_Initialize() For Each c In ActiveWorkbook.VBProject.VBComponents For ligne = 1 To c.CodeModule.CountOfLines temp = Trim(c.CodeModule.Lines(ligne, 1)) If Left(temp, 3) = "Sub" Then Me.ComboBox1.AddItem Mid(Left(temp, Len(temp) - 2), 4) Next Next End Sub
JB
On 24 sep, 20:12, "Herve" wrote:
Bonjour, Je souhaite obtenir dans une liste déroulante d'un UserForm les noms de toutes les macros contenues dans le classeur courant. Comment peut-on faire ?