OVH Cloud OVH Cloud

Erreur macro createBO

5 réponses
Avatar
Le Surcitaire
Re bonjour,

j'ai encore besoin de votre aide
Quand je ferme mon classeur j'ai une erreur dans cette macro et je ne
vois pas pourquoi :-[

erreur d'execution 5
Argument ou appel de procedure incorrect

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CommandBars(nomBO).Visible = False
End Sub

--
enlever lesurcitaire
La Vie n'est rien sans la joie de vivre

5 réponses

Avatar
Quetzalcoatl
As-tu qqchose comme "CreateBO" exécuté *avant* ?
avec :

Public Const nomBO As String = "tu y mets ce que tu veux, c'est vous qui voyez"
Sub CreateBO()
Dim tb As CommandBar
Dim statusBarInitial As Boolean
On Error Resume Next
DeleteBO 'in case Excel crashed :-)
Set tb = Application.CommandBars.Add(name:=nomBO, Position:=msoBarTop)
With tb.Controls.Add(msoControlButton)
.style = msoButtonIconAndCaption
.Caption = "qu'est ce que tu veux mettre comme Caption ?"
.FaceId = 25 'à choisir
.OnAction = "Qu'est-ce que tu veux mettre comme OnAction ? Hein ?"
.TooltipText = "Qu'est-ce que tu veux y mettre là comme TooltipText ?
Hein ? Hein ?"
End With
tb.Visible = True
End Sub
Sub DeleteBO()
On Error Resume Next
Application.CommandBars(nomBO).Delete
End Sub

erreur d'execution 5
Argument ou appel de procedure incorrect

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CommandBars(nomBO).Visible = False
End Sub


--
Adiós

Avatar
Le Surcitaire
Oui j'ai bien cela

Dans ThisWorkbook:
***************************************************
Private Sub Workbook_Open()
CreateBO
Sheets("AAIntro").Select
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CommandBars(nomBO).Visible = True
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CommandBars(nomBO).Visible = False
End Sub

Private Sub Workbook_Activate()
'* Set the window text
SetWindowText GetActiveWindow, "Casernement - CS St Julien -
Habillement"
Dim Barre As CommandBar
Set Barres = New Collection
For Each Barre In Application.CommandBars
If Barre.Visible = True And _
Barre.Name <> "Worksheet Menu Bar" Then
Barres.Add Barre.Name
Barre.Visible = False

End If
Next Barre
Application.CommandBars("worksheet menu bar").Enabled = True
End Sub

Private Sub Workbook_Deactivate()
Dim Barre As Variant
For Each Barre In Barres
Application.CommandBars(Barre).Visible = True
Next Barre
Application.CommandBars("worksheet menu bar").Enabled = True
End Sub

et dans une module appele Bo:

*****************************************************************
Private Sub Nouveau()
msg = "Vous allez créer une nouvelle feuille à partir de ce modèle
" & vbCrLf & vbCrLf & "Comment voulez nommer cette feuille ? " & vbCrLf
& "Entrer le Nom"
Rep = InputBox(msg, "Saisie du Nom")
msg2 = "Vous allez créer une nouvelle feuille à partir de ce modèle
" & vbCrLf & vbCrLf & "Comment voulez nommer cette feuille ? " & vbCrLf
& "Entrer le Prénom"
Repb = InputBox(msg2, "Saisie du Prénom")
If Rep = "" Then Exit Sub
On Error GoTo SaisieInvalide
Application.ScreenUpdating = False
Sheets("Modèle").Copy Before:=Worksheets("XFin")
ActiveSheet.Name = Rep & Repb
Ajouter_Lien (ActiveSheet.Name)

Exit Sub
SaisieInvalide:
Application.ScreenUpdating = True
Application.DisplayAlerts = False
ActiveSheet.Delete
msg = "Le nom que vous avez tapé n'est pas valide !" & vbCrLf &
vbCrLf & "-Vérifier que le nom de la feuille ne dépasse " & "pas _31
caractères " & vbCrLf & "-Vérifier que le nom de la feuille ne contient
" & "aucun des caractères suivants :" & vbCrLf & " ,/ : ?* [ ou ]" &
vbCrLf & "-Vérifier qu'une feuille du classeur ne possède " & "pas déjà
un nom identique"
Reponse = MsgBox(msg, , "Saisie invalide")
Sheets("Modèle").Select
Exit Sub
End Sub

Private Sub Trier()
TrierSauf2
End Sub


Private Sub Imprime()
Reponse = Application.Dialogs(xlDialogPrint).Show
End Sub

Private Sub Save()
ActiveWorkbook.Save
End Sub

Private Sub Fermer()
ThisWorkbook.Close
End Sub


Dans un autre module appele Habillement:

******************************************************
Public Const nomBO = "Habillement"

Sub CreateBO()
Dim Bo As CommandBar
On Error Resume Next
DeleteBO 'en cas de plantage d'Excel :-)

Set Bo = Application.CommandBars.Add
With Bo.Controls.Add(msoControlButton)
.Caption = "Nouvelle Fiche"
.FaceId = 191
.OnAction = "Nouveau"
End With
With Bo.Controls.Add(msoControlButton)
.Caption = "Imprimer"
.FaceId = 4
.OnAction = "Imprime"
End With
BeginGroup = True
With Bo.Controls.Add(msoControlButton)
.Caption = "Enregistrer"
.FaceId = 3
.OnAction = "Save"
End With
With Bo.Controls.Add(msoControlButton)
.Caption = "Trier les Onglets"
.FaceId = 654
.OnAction = "TrierSauf2"
End With
With Bo.Controls.Add(msoControlButton)
.Caption = "Fermer"
.FaceId = 840
.OnAction = "Fermer"
End With
Bo.Visible = True
End Sub

Sub DeleteBO()
On Error Resume Next
Application.CommandBars(nomBO).Delete
End Sub

--
enlever lesurcitaire
La Vie n'est rien sans la joie de vivre
Avatar
Quetzalcoatl
Pour masquer une barre d'outils qui a pour nom "nomBO" :
Application.CommandBars(nomBO).Visible = False
il faut que tu lui aies donné ce nom lors de sa création :
Set Bo = Application.CommandBars.Add(name:=nameBO)

Dis-nous si ça le fait.

Oui j'ai bien cela
--

Do widzenia

Avatar
Quetzalcoatl
Oupsss ! petite correction :

Pour masquer une barre d'outils qui a pour nom "nomBO" :
Application.CommandBars(nomBO).Visible = False
il faut que tu lui aies donné ce nom lors de sa création :
Set Bo = Application.CommandBars.Add(name:=nomBO)

--
Adessiatz
Avatar
Le Surcitaire
Quetzalcoatl avait prétendu :
Set Bo = Application.CommandBars.Add(name:=nomBO)


Oui cela marche mais j'ai une autre erreur
Private Sub Workbook_Deactivate()
Dim Barre As Variant
For Each Barre In Barres <- ici
Application.CommandBars(Barre).Visible = True
Next Barre
Application.CommandBars("worksheet menu bar").Enabled = True
End Sub

--
enlever lesurcitaire
La Vie n'est rien sans la joie de vivre