OVH Cloud OVH Cloud

custom toolbar problem

4 réponses
Avatar
crahay
Hi,

When sending to another PC a file including a customized
toolbaar (multilevel menus), I lose some of the submenus
and the path of the macro that was assigned to them.

Thank you for your help !

4 réponses

Avatar
mousnynao
Hello,

My english is poor but i will try to explain you
something!

To correct this thing, i suggest that you will create
the toolbar by sub at the opening of the workbook and
destroy them at the closure of the workbook.

Here an exemple (the comment are in french) :

'**************************************************
Public Sub Workbook_Open()

Dim Boucle, NumPage, NumBarre As Integer
Dim TexteBouton As String
Dim ChaineCommande As String
Dim Exemple As String
Dim CodeBouton As Integer
Dim TexteAideBouton

DetruitBarre

Application.CommandBars.Add(Name:="Bloc").Visible = True
Application.CommandBars("Bloc").Position = msoBarTop

'Ajout d'un bouton dans la barre d'ouitls principal
'de la page EXPLORATION
' Premier bouton du couple qui sert à créer la série
' de barres d'outils (NumBarre) de la page (NumPage)
Application.CommandBars("Bloc").Controls.Add
Type:=msoControlButton, ID:)50, Before:=Boucle

'Création du texte du bouton, de la propriété VB
'<.Caption>, gestion de la page(NumPage)
TexteBouton = "Créer la page " & NumPage

'Affectation du texte du bouton, à la propriété VBA
'<.Caption>, gestion de la page(NumPage)

Application.CommandBars("Bloc").Controls(Boucle).Caption =
TexteBouton

'Création de la chaine de commande pour la propriété VBA
'<.OnAction>
ChaineCommande = "'CreationPageBarreOutils " & "(" & """"
& NumPage & """" & ")'"

'Affectation de la chaine de commande à la propriété VBA
'<.OnAction>

Application.CommandBars("Bloc").Controls(Boucle).OnAction
= ChaineCommande

'Création du code du bouton pour la propriété VBA <.FaceId>
CodeBouton = (cteClef + NumPage) 'Constante pour obtenir
'les chiffres et lettres de 1 à K

'Affectation du code du bouton, à la propriété VBA
'<.FaceId>

Application.CommandBars("Bloc").Controls(Boucle).FaceId =
CodeBouton '1253 = Logo de passage

'Création du style de présentation
'msoButtonCaption est une constante VBA qui signifie
'd'afficher la propriété <.Caption> comme icon sur le
bouton

'Affectation du style de présentation ( si omis affichage
de l'icon, propeiété <.FaceId>)

'Application.CommandBars("Bloc").Controls(boucle).Style =
msoButtonCaption

'Création du texte de l'info-bulle du bouton, la propriété
<.TooltipText>
TexteAideBouton = "Créer la page " & NumPage & " des
barres d'outils de " & NumBarre & " à " & (NumBarre + 19)
'Affectation du texte de l'info-bulle du bouton, à la
propriété <.TooltipText>
Application.CommandBars("Bloc").Controls
(Boucle).TooltipText = TexteAideBouton

'Création de la propriété VBA <.Enabled>
'Valeur TRUE ou FALSE
'Affectation de la propriété VBA <.Enabled>
Application.CommandBars("Bloc").Controls(Boucle).Enabled =
False


'Ajout d'un bouton dans la barre d'ouitls principal de la
page EXPLORATION
' Deuxièeme bouton du couple qui sert à détruire la série
' de barres d'outils (NumBarre) de la page (NumPage)

Application.CommandBars("Bloc").Controls.Add
Type:=msoControlButton, ID:)50, Before:=(Boucle + 1)
TexteBouton = "Destruction de la page " & NumPage
Application.CommandBars("Bloc").Controls(Boucle +
1).Caption = TexteBouton

ChaineCommande = "'DetruitBarreOutils " & "(" & """" &
NumPage & """" & ")'"

Application.CommandBars("Bloc").Controls(Boucle +
1).OnAction = ChaineCommande

CodeBouton = 1254 'Logo interdit de passage

Application.CommandBars("Bloc").Controls(Boucle +
1).FaceId = CodeBouton

'Application.CommandBars("Bloc").Controls(Boucle +
1).Style = msoButtonCaption

TexteAideBouton = "Détruire la page " & NumPage & " des
barres d'outils de " & NumBarre & " à " & (NumBarre + 19)

Application.CommandBars("Bloc").Controls(Boucle +
1).TooltipText = TexteAideBouton

'Création de la propriété VBA <.Enabled>
'Valeur TRUE ou FALSE
'Affectation de la propriété VBA <.Enabled>
Application.CommandBars("Bloc").Controls(Boucle).Enabled
= True

Next

End Sub
'----------------------------------------
Sub DetruitBarre ()

Dim Barre As Variant

For Each Barre In Application.CommandBars
If (Barre.Name = "Bloc") Then
Application.CommandBars("Bloc").Delete
Exit For
End If
Next

End Sub
'---------------------------------------------------
Public Sub Workbook_BeforeClose(Cancel As Boolean)
DetruitBarre
End Sub
'******************************************************

So, be carefull if you use cut/paste with the comment ...

@+
mousnynao
-----Message d'origine-----
Hi,

When sending to another PC a file including a customized
toolbaar (multilevel menus), I lose some of the submenus
and the path of the macro that was assigned to them.

Thank you for your help !
.



Avatar
Clément Marcotte
Un autre trop paresseux pour écrire en français.


"" a écrit
dans le message de news:ea1601c3f163$05d02810$
Hi,

When sending to another PC a file including a customized
toolbaar (multilevel menus), I lose some of the submenus
and the path of the macro that was assigned to them.

Thank you for your help !


Avatar
Clément Marcotte
En principe, à l'Université catholique de Louvain, ils parlent
français. S'ils admettent des têtes carrées, qu'ils s'arrangent pour
que leurs têtes carrées apprennent le français avant.


"mousnynao" a écrit dans le
message de news:f62301c3f16f$c5c48380$
Hello,

My english is poor but i will try to explain you
something!

To correct this thing, i suggest that you will create
the toolbar by sub at the opening of the workbook and
destroy them at the closure of the workbook.

Here an exemple (the comment are in french) :

'**************************************************
Public Sub Workbook_Open()

Dim Boucle, NumPage, NumBarre As Integer
Dim TexteBouton As String
Dim ChaineCommande As String
Dim Exemple As String
Dim CodeBouton As Integer
Dim TexteAideBouton

DetruitBarre

Application.CommandBars.Add(Name:="Bloc").Visible = True
Application.CommandBars("Bloc").Position = msoBarTop

'Ajout d'un bouton dans la barre d'ouitls principal
'de la page EXPLORATION
' Premier bouton du couple qui sert à créer la série
' de barres d'outils (NumBarre) de la page (NumPage)
Application.CommandBars("Bloc").Controls.Add
Type:=msoControlButton, ID:)50, Before:=Boucle

'Création du texte du bouton, de la propriété VB
'<.Caption>, gestion de la page(NumPage)
TexteBouton = "Créer la page " & NumPage

'Affectation du texte du bouton, à la propriété VBA
'<.Caption>, gestion de la page(NumPage)

Application.CommandBars("Bloc").Controls(Boucle).Caption TexteBouton

'Création de la chaine de commande pour la propriété VBA
'<.OnAction>
ChaineCommande = "'CreationPageBarreOutils " & "(" & """"
& NumPage & """" & ")'"

'Affectation de la chaine de commande à la propriété VBA
'<.OnAction>

Application.CommandBars("Bloc").Controls(Boucle).OnAction
= ChaineCommande

'Création du code du bouton pour la propriété VBA <.FaceId>
CodeBouton = (cteClef + NumPage) 'Constante pour obtenir
'les chiffres et lettres de 1 à K

'Affectation du code du bouton, à la propriété VBA
'<.FaceId>

Application.CommandBars("Bloc").Controls(Boucle).FaceId CodeBouton '1253 = Logo de passage

'Création du style de présentation
'msoButtonCaption est une constante VBA qui signifie
'd'afficher la propriété <.Caption> comme icon sur le
bouton

'Affectation du style de présentation ( si omis affichage
de l'icon, propeiété <.FaceId>)

'Application.CommandBars("Bloc").Controls(boucle).Style msoButtonCaption

'Création du texte de l'info-bulle du bouton, la propriété
<.TooltipText>
TexteAideBouton = "Créer la page " & NumPage & " des
barres d'outils de " & NumBarre & " à " & (NumBarre + 19)
'Affectation du texte de l'info-bulle du bouton, à la
propriété <.TooltipText>
Application.CommandBars("Bloc").Controls
(Boucle).TooltipText = TexteAideBouton

'Création de la propriété VBA <.Enabled>
'Valeur TRUE ou FALSE
'Affectation de la propriété VBA <.Enabled>
Application.CommandBars("Bloc").Controls(Boucle).Enabled False


'Ajout d'un bouton dans la barre d'ouitls principal de la
page EXPLORATION
' Deuxièeme bouton du couple qui sert à détruire la série
' de barres d'outils (NumBarre) de la page (NumPage)

Application.CommandBars("Bloc").Controls.Add
Type:=msoControlButton, ID:)50, Before:=(Boucle + 1)
TexteBouton = "Destruction de la page " & NumPage
Application.CommandBars("Bloc").Controls(Boucle +
1).Caption = TexteBouton

ChaineCommande = "'DetruitBarreOutils " & "(" & """" &
NumPage & """" & ")'"

Application.CommandBars("Bloc").Controls(Boucle +
1).OnAction = ChaineCommande

CodeBouton = 1254 'Logo interdit de passage

Application.CommandBars("Bloc").Controls(Boucle +
1).FaceId = CodeBouton

'Application.CommandBars("Bloc").Controls(Boucle +
1).Style = msoButtonCaption

TexteAideBouton = "Détruire la page " & NumPage & " des
barres d'outils de " & NumBarre & " à " & (NumBarre + 19)

Application.CommandBars("Bloc").Controls(Boucle +
1).TooltipText = TexteAideBouton

'Création de la propriété VBA <.Enabled>
'Valeur TRUE ou FALSE
'Affectation de la propriété VBA <.Enabled>
Application.CommandBars("Bloc").Controls(Boucle).Enabled
= True

Next

End Sub
'----------------------------------------
Sub DetruitBarre ()

Dim Barre As Variant

For Each Barre In Application.CommandBars
If (Barre.Name = "Bloc") Then
Application.CommandBars("Bloc").Delete
Exit For
End If
Next

End Sub
'---------------------------------------------------
Public Sub Workbook_BeforeClose(Cancel As Boolean)
DetruitBarre
End Sub
'******************************************************

So, be carefull if you use cut/paste with the comment ...

@+
mousnynao
-----Message d'origine-----
Hi,

When sending to another PC a file including a customized
toolbaar (multilevel menus), I lose some of the submenus
and the path of the macro that was assigned to them.

Thank you for your help !
.



Avatar
Merci beaucoup pour cette proposition.

Je vais l'appliquer, car elle permet beaucoup plus de
souplesse que l'exportation pure et simple.

Amicalement, André