sh4gm4
Messages postés47Date d'inscriptionlundi 21 juillet 2008StatutMembreDernière intervention 2 octobre 2008
-
31 juil. 2008 à 17:37
sh4gm4
Messages postés47Date d'inscriptionlundi 21 juillet 2008StatutMembreDernière intervention 2 octobre 2008
-
1 août 2008 à 09:33
Salut,
je cherche un moyen de récupérer dynamiquement depuis le soft que je développe en C#
la liste des macros disponibles que ce soit dans le document lui même ou dans le normal.dot
MERCI d'avance ;)
A voir également:
récupérer la liste des macros accessible dans word
bigfish_le vrai
Messages postés1835Date d'inscriptionvendredi 13 mai 2005StatutMembreDernière intervention20 novembre 201315 31 juil. 2008 à 18:43
Salut,
je suis en train de travailler sur un fichier excel qui permet de mettre a jour les macro d'un autre fichier excel utilisé par une 20aine d'utilisateurs. pour expliquer un peu le principe :
l'utilisateur a sa propre copie du dit fichier, en local, sur sont pc. Quand l'utilisateur ouvre sont fichier excel celui ci va verifier sur le reseau si une mise a jour existe. Si une mise a jour existe le fichier vas ouvrir un fichier text qui ce trouve sur le reseau et qui contient les mises jour. Concernant le fichier text celui-ci est generer a partir d'un autre fichier excel utilisé uniquement par l'administrateur et qui via une petite interface lui permet de creer modifier ou supprimer les macro et donc de generer ce fichier text. Donc ci-dessous quelque bout de code provenant de ce projet :
Sub ActiveRef() 'activation of the reference *Microsoft Visual Basic for Applications Extensibility 5.3*
Dim MyRef As String, RefPath As String, TypeError As String
RefPath = "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6"
MyRef = "Vbe6ext.olb"
MyRef = Dir(RefPath & MyRef)
If MyRef <> "" Then
Application.DisplayAlerts = False
On Local Error Resume Next
ThisWorkbook.VBProject.References.AddFromFile RefPath & MyRef
If Err = 1004 Then
Err.Clear
TypeError = " The Reference could not be added "
MsgBox TypeError & " or the Trust access to Visual Basic Project is disable or both !" _
& vbCrLf & vbCrLf & "In order to allow the activation of the references, follow the process below :" & vbCrLf _
& vbCrLf & "Point to Macro on the Tools menu, and then click Security." _
& vbCrLf & "On the Trusted Publishers tab, check the Trust access to Visual Basic Project box. " _
& vbCrLf & vbCrLf & "For more information please contact your Administrator", vbExclamation, "Reference Missing..."
TypeError = " The Reference could not be added "
Else
TypeError = " **Reference Activated** "
End If
Application.DisplayAlerts = True
Else
TypeError = " Reference not found "
End If
Application.DisplayAlerts = False
RecError (TypeError)
End Sub
Sub RecError(ByVal TypeError As String) 'error report
Dim CMDAppli As Double, CurrentPath As String, ErrorFile As String, MsgError As String, NbSub As Long
CurrentPath = ThisWorkbook.Path & ""
ErrorFile = "Error.txt"
MsgError = Now & TypeError & ThisWorkbook.Name
CMDAppli = Shell("cmd.exe /c echo " & MsgError & " >> " & ErrorFile, 0)
End
End Sub
Sub CreatListCombobox3() 'Creation of the macro list
Dim VBAComp As Object
Dim VBAMacro As Object, NbCodeLine As Long, i As Long, SubName As String
Dim n As Long, MyTab As String
MyTab = Chr(32) & Chr(32) '2 spaces
If Err <> 0 Then
ActiveRef
Exit Sub
End If
n = 0
On Local Error Resume Next
For Each VBAComp In ThisWorkbook.VBProject.VBComponents
If Err <> 0 Then
ActiveRef
Exit Sub
End If
UserForm1.ComboBoxListMacro.AddItem VBAComp.Name
With VBAComp.CodeModule
NbCodeLine = .CountOfLines
For i = 1 To NbCodeLine
If Left(.Lines(i, 1), 3) = "Sub" Then
SubName = Replace(.Lines(i, 1), "Sub ", MyTab)
SubName = Left(SubName, Application.Search("(", SubName, 1) - 1)
UserForm1.ComboBoxListMacro.AddItem SubName
ElseIf Left(.Lines(i, 1), 11) = "Private Sub" Then
SubName = Replace(.Lines(i, 1), "Private Sub ", MyTab)
SubName = Left(SubName, Application.Search("(", SubName, 1) - 1)
UserForm1.ComboBoxListMacro.AddItem SubName
End If
Next
End With
n = n + 1
Next
End Sub
evidemment tous ceci est loin d'estre optimiser mais devrait te permetre de trouver ce que tu cherches