OVH Cloud OVH Cloud

Une autre ? Déprotéger le projet par VBA

4 réponses
Avatar
Joel
Bonjour (re LOL ) !

Une idée pour désactiver la protection du VBProject dans lequel la macro
s'exécute par macro... ?

Car il semble bien que si le projet est protégé, on ne puisse pas supprimer
une référence... toujours elles ;-)

Encore une fois Merci

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr

4 réponses

Avatar
Michel Pierron
Bonsoir Joel;
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function Putfocus& Lib "user32" Alias _
"SetFocus" (ByVal hwnd&)

Private Sub VbaUnlock(ByVal Wbk$, ByVal PWord$)
If Workbooks(Wbk).VBProject.Protection = 0 Then Exit Sub
Set Application.VBE.ActiveVBProject = Workbooks(Wbk).VBProject
SendKeys PWord & "~~"
Application.VBE.CommandBars(1).FindControl(ID:%78,
recursive:=True).Execute
End Sub

Sub Essai()
VbaUnlock "Test1.xls", "Roudoudou"
Dim l&: l = Timer
While Timer < l + 1: DoEvents: Wend
Putfocus FindWindow(vbNullString, Application.Caption)
End Sub

Pour les références, tu peux peut être t'inspirer de ceci:
Sub ListRef()
GetProjectReferences ThisWorkbook.Name
End Sub

Private Sub GetProjectReferences(ByVal Wbk$)
Dim oRef As Object, sType$, i&
Workbooks.Add
For Each oRef In Workbooks(Wbk).VBProject.References
With oRef
i = i + 1
Cells(i, 1) = .Name & " " & .Major & "." & .Minor
Cells(i, 1).Font.Bold = True
If Not .IsBroken And .Description <> "" Then
i = i + 1: Cells(i, 2) = .Description
End If
If .BuiltIn Then sType = "Intégré (" Else sType = "Personnalisé ("
i = i + 1
Select Case .Type
Case 1: sType = sType & "Projet)"
Case 0: sType = sType & "TypeLib)"
End Select
If .IsBroken Then
sType = sType & " - Référence rompue"
Else
sType = sType & " - Référence intacte"
End If
Cells(i, 2) = sType
i = i + 1: Cells(i, 2) = .FullPath
If .Type = 0 Then: i = i + 1: Cells(i, 2) = .GUID
End With
i = i + 1
Next
Columns("A:A").ColumnWidth = 2
End Sub

MP

"Joel" a écrit dans le message de
news:cdtveu$mln$
Bonjour (re LOL ) !

Une idée pour désactiver la protection du VBProject dans lequel la macro
s'exécute par macro... ?

Car il semble bien que si le projet est protégé, on ne puisse pas
supprimer

une référence... toujours elles ;-)

Encore une fois Merci

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr




Avatar
Joel
Merci Michel j'essaye cela demain !!!

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr
"Michel Pierron" a écrit dans le message de
news:
Bonsoir Joel;
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function Putfocus& Lib "user32" Alias _
"SetFocus" (ByVal hwnd&)

Private Sub VbaUnlock(ByVal Wbk$, ByVal PWord$)
If Workbooks(Wbk).VBProject.Protection = 0 Then Exit Sub
Set Application.VBE.ActiveVBProject = Workbooks(Wbk).VBProject
SendKeys PWord & "~~"
Application.VBE.CommandBars(1).FindControl(ID:%78,
recursive:=True).Execute
End Sub

Sub Essai()
VbaUnlock "Test1.xls", "Roudoudou"
Dim l&: l = Timer
While Timer < l + 1: DoEvents: Wend
Putfocus FindWindow(vbNullString, Application.Caption)
End Sub

Pour les références, tu peux peut être t'inspirer de ceci:
Sub ListRef()
GetProjectReferences ThisWorkbook.Name
End Sub

Private Sub GetProjectReferences(ByVal Wbk$)
Dim oRef As Object, sType$, i&
Workbooks.Add
For Each oRef In Workbooks(Wbk).VBProject.References
With oRef
i = i + 1
Cells(i, 1) = .Name & " " & .Major & "." & .Minor
Cells(i, 1).Font.Bold = True
If Not .IsBroken And .Description <> "" Then
i = i + 1: Cells(i, 2) = .Description
End If
If .BuiltIn Then sType = "Intégré (" Else sType = "Personnalisé ("
i = i + 1
Select Case .Type
Case 1: sType = sType & "Projet)"
Case 0: sType = sType & "TypeLib)"
End Select
If .IsBroken Then
sType = sType & " - Référence rompue"
Else
sType = sType & " - Référence intacte"
End If
Cells(i, 2) = sType
i = i + 1: Cells(i, 2) = .FullPath
If .Type = 0 Then: i = i + 1: Cells(i, 2) = .GUID
End With
i = i + 1
Next
Columns("A:A").ColumnWidth = 2
End Sub

MP

"Joel" a écrit dans le message de
news:cdtveu$mln$
Bonjour (re LOL ) !

Une idée pour désactiver la protection du VBProject dans lequel la macro
s'exécute par macro... ?

Car il semble bien que si le projet est protégé, on ne puisse pas
supprimer

une référence... toujours elles ;-)

Encore une fois Merci

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr








Avatar
Joel
Bonjour Michel et grand merci pour cette aide.

Concernant l'aspect Référence, il semble bien que tout ne soit que théorie,
car pour moi, cela plante systématiquement sur :

Cells(i, 1) = .Name & " " & .Major & "." & .Minor

si la référence est manquante, il est impossible de lire la propriété Name
(et donc impossible d'appliquer la méthode Remove à cette référence)

C'est pourquoi j'aimerais bien savoir si quelqu'un a déjà utilisé ce code
avec succès sur une référence manquante.

Pour la partie déprotéger le projet VB cela fonctionne impec.

Merci pour tout et bon dimanche...en attendant d'éventuelles lumières sur
ces références manquantes qui gâchent mon week-end !!!
--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr
"Michel Pierron" a écrit dans le message de
news:
Bonsoir Joel;
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function Putfocus& Lib "user32" Alias _
"SetFocus" (ByVal hwnd&)

Private Sub VbaUnlock(ByVal Wbk$, ByVal PWord$)
If Workbooks(Wbk).VBProject.Protection = 0 Then Exit Sub
Set Application.VBE.ActiveVBProject = Workbooks(Wbk).VBProject
SendKeys PWord & "~~"
Application.VBE.CommandBars(1).FindControl(ID:%78,
recursive:=True).Execute
End Sub

Sub Essai()
VbaUnlock "Test1.xls", "Roudoudou"
Dim l&: l = Timer
While Timer < l + 1: DoEvents: Wend
Putfocus FindWindow(vbNullString, Application.Caption)
End Sub

Pour les références, tu peux peut être t'inspirer de ceci:
Sub ListRef()
GetProjectReferences ThisWorkbook.Name
End Sub

Private Sub GetProjectReferences(ByVal Wbk$)
Dim oRef As Object, sType$, i&
Workbooks.Add
For Each oRef In Workbooks(Wbk).VBProject.References
With oRef
i = i + 1
Cells(i, 1) = .Name & " " & .Major & "." & .Minor
Cells(i, 1).Font.Bold = True
If Not .IsBroken And .Description <> "" Then
i = i + 1: Cells(i, 2) = .Description
End If
If .BuiltIn Then sType = "Intégré (" Else sType = "Personnalisé ("
i = i + 1
Select Case .Type
Case 1: sType = sType & "Projet)"
Case 0: sType = sType & "TypeLib)"
End Select
If .IsBroken Then
sType = sType & " - Référence rompue"
Else
sType = sType & " - Référence intacte"
End If
Cells(i, 2) = sType
i = i + 1: Cells(i, 2) = .FullPath
If .Type = 0 Then: i = i + 1: Cells(i, 2) = .GUID
End With
i = i + 1
Next
Columns("A:A").ColumnWidth = 2
End Sub

MP

"Joel" a écrit dans le message de
news:cdtveu$mln$
Bonjour (re LOL ) !

Une idée pour désactiver la protection du VBProject dans lequel la macro
s'exécute par macro... ?

Car il semble bien que si le projet est protégé, on ne puisse pas
supprimer

une référence... toujours elles ;-)

Encore une fois Merci

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr








Avatar
Joel
Encore une fois MERCI Michel, car sans répondre véritablement à toutes mes
interrogations concernant ces histoires de références manquantes qu'on ne
peut pas supprimer, tu m'as laissé des pistes qui devraient me permettre de
résoudre, indirectement, ce problème.

en gros, avant de démarrer l'appli Word à partir d'excel, je recherche la
bibliothèque MSWORD?.OLB sur le disque dur de l'utilisateur, l'installe, et
la supprime après le travail effectué sur Word...

Je commençais à désepérer de trouver une solution viable, je pense
maintenant la tenir.

Bon après-midi et merci encore...

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr
"Michel Pierron" a écrit dans le message de
news:
Bonsoir Joel;
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function Putfocus& Lib "user32" Alias _
"SetFocus" (ByVal hwnd&)

Private Sub VbaUnlock(ByVal Wbk$, ByVal PWord$)
If Workbooks(Wbk).VBProject.Protection = 0 Then Exit Sub
Set Application.VBE.ActiveVBProject = Workbooks(Wbk).VBProject
SendKeys PWord & "~~"
Application.VBE.CommandBars(1).FindControl(ID:%78,
recursive:=True).Execute
End Sub

Sub Essai()
VbaUnlock "Test1.xls", "Roudoudou"
Dim l&: l = Timer
While Timer < l + 1: DoEvents: Wend
Putfocus FindWindow(vbNullString, Application.Caption)
End Sub

Pour les références, tu peux peut être t'inspirer de ceci:
Sub ListRef()
GetProjectReferences ThisWorkbook.Name
End Sub

Private Sub GetProjectReferences(ByVal Wbk$)
Dim oRef As Object, sType$, i&
Workbooks.Add
For Each oRef In Workbooks(Wbk).VBProject.References
With oRef
i = i + 1
Cells(i, 1) = .Name & " " & .Major & "." & .Minor
Cells(i, 1).Font.Bold = True
If Not .IsBroken And .Description <> "" Then
i = i + 1: Cells(i, 2) = .Description
End If
If .BuiltIn Then sType = "Intégré (" Else sType = "Personnalisé ("
i = i + 1
Select Case .Type
Case 1: sType = sType & "Projet)"
Case 0: sType = sType & "TypeLib)"
End Select
If .IsBroken Then
sType = sType & " - Référence rompue"
Else
sType = sType & " - Référence intacte"
End If
Cells(i, 2) = sType
i = i + 1: Cells(i, 2) = .FullPath
If .Type = 0 Then: i = i + 1: Cells(i, 2) = .GUID
End With
i = i + 1
Next
Columns("A:A").ColumnWidth = 2
End Sub

MP

"Joel" a écrit dans le message de
news:cdtveu$mln$
Bonjour (re LOL ) !

Une idée pour désactiver la protection du VBProject dans lequel la macro
s'exécute par macro... ?

Car il semble bien que si le projet est protégé, on ne puisse pas
supprimer

une référence... toujours elles ;-)

Encore une fois Merci

--

Bien cordialement,

Joël GARBE
www.joelgarbe.fr