Déprotégé PROJET pour Module Ajout

B

Blandine

Guest
Quel est le code pour déprotégé un Projet

afin de le mettre à jour en y ajoutant un module ?


==========================
HISTORIQUE DES PRECEDENTS POST :


Auteur: STéphane
Date: 17-10-02 16:01

bonjour

il y a moyen tordu de le faire, vous pourrez trouver un exemple je pense chez fréd sigonneau

je pense avoir mis une des premières versions de cette bidouille également sur mon site il y a fort longtemps


bye
stephane









Auteur: Gérard
Date: 17-10-02 16:36

Il doit certainement s'agir de ce code
'=================================================
'Laurent Longre, mpfe

Private Declare Function FindWindowA Lib "User32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function GetForegroundWindow Lib "User32" () As Long

Private Declare Function SetForegroundWindow Lib "User32" _
(ByVal hWnd As Long) As Long


Function Déprotège(Classeur As String, MdP As String) As Boolean

Dim XLhWnd As Long, VBEhWnd As Long, CurhWnd As Long
Dim Wbk As Workbook

On Error Resume Next
Set Wbk = Workbooks(Dir$(Classeur))
On Error GoTo Fin
If Not Wbk Is Nothing Then
If Wbk.FullName <> Classeur Then Exit Function
If Not Wbk.Saved Then Wbk.Save
Else: Application.ScreenUpdating = False
End If

CurhWnd = GetForegroundWindow
XLhWnd = FindWindowA(vbNullString, Application.Caption)

With Application.VBE
VBEhWnd = FindWindowA(vbNullString, .MainWindow.Caption)
If CurhWnd = XLhWnd Then SetForegroundWindow VBEhWnd
.CommandBars.FindControl(ID:=2557).Execute
' NE PAS EFFACER, même si le classeur est déjà ouvert !!!!!!
Workbooks.Open Classeur
If ActiveWorkbook.VBProject.Protection = vbext_pp_locked Then
SendKeys "~" & MdP & "~", True
.ActiveCodePane.Window.Close
End If
End With

SetForegroundWindow CurhWnd
Déprotège = True
Exit Function

Fin:
End Function



Sub test()

' Déprotection du projet VBA C:\Temp\Test.xls (mot de passe "zaza"),
' Ajout d'un module standard dans ce projet, puis rétablissement
' de la protection

Const Classeur = "C:\Temp\Test.xls"
If Not Déprotège(Classeur, "zaza") Then
MsgBox "Erreur"
Else
MsgBox "Projet VBA déprotégé."
With Workbooks(Dir$(Classeur))
.VBProject.VBComponents.Add vbext_ct_StdModule
.Close True
End With
Workbooks.Open Classeur
MsgBox "Projet reprotégé, ajout d'un module standard."
End If

End Sub

'=================================================
 
B

Blandine

Guest
MERCI à STéphane, Ti et Gérard

grace à qui je peux avancer sur ce projet...


MAIS MALHEUREUSEMENT bien qu'un MsgBox signale

le projet déprotégé, VBA signale une erreur

au moment de l'ajout d'un module...

COMMENT MODIFIER CES LIGNES DE CODES ?


MERCI...
BLandine
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
313 105
Messages
2 095 348
Membres
106 246
dernier inscrit
Christelle CUPIT