Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Execution Control et erreur 5

4 réponses
Avatar
manu
Bonjour, le code suivant:

Application.CommandBars("Worksheet Menu Bar").Controls("Format"). _
Controls("&Forme automatique...").Execute

Provoque une erreur 5 si je n'ai pas "initi=E9" au moins une fois Excel
en effectuant la manip correspondante =E0 la main, cad en clickant avec
ma souris sur le menu "Format" puis "Forme automatique".
Comment faire son "Initiation" via le code ?

Merci d'avance.

4 réponses

Avatar
isabelle
bonjour manu,

Selection.AutoFormat Format:=xlRangeAutoFormatClassic1, Number:=True, Font _
:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True

__________________________________________________________________________________

XlRangeAutoFormat peut être l'une de ces constantes XlRangeAutoFormat.

xlRangeAutoFormat3DEffects1
xlRangeAutoFormat3DEffects2
xlRangeAutoFormatAccounting1
xlRangeAutoFormatAccounting2
xlRangeAutoFormatAccounting3
xlRangeAutoFormatAccounting4
xlRangeAutoFormatClassic1 par défaut
xlRangeAutoFormatClassic2
xlRangeAutoFormatClassic3
xlRangeAutoFormatClassicPivotTable
xlRangeAutoFormatColor1
xlRangeAutoFormatColor2
xlRangeAutoFormatColor3
xlRangeAutoFormatList1
xlRangeAutoFormatList2
xlRangeAutoFormatList3
xlRangeAutoFormatLocalFormat1
xlRangeAutoFormatLocalFormat2
xlRangeAutoFormatLocalFormat3
xlRangeAutoFormatLocalFormat4
xlRangeAutoFormatNone
xlRangeAutoFormatPTNone
xlRangeAutoFormatReport1
xlRangeAutoFormatReport10
xlRangeAutoFormatReport2
xlRangeAutoFormatReport3
xlRangeAutoFormatReport4
xlRangeAutoFormatReport5
xlRangeAutoFormatReport6
xlRangeAutoFormatReport7
xlRangeAutoFormatReport8
xlRangeAutoFormatReport9
xlRangeAutoFormatSimple
xlRangeAutoFormatTable1
xlRangeAutoFormatTable10
xlRangeAutoFormatTable2
xlRangeAutoFormatTable3
xlRangeAutoFormatTable4
xlRangeAutoFormatTable5
xlRangeAutoFormatTable6
xlRangeAutoFormatTable7
xlRangeAutoFormatTable8
xlRangeAutoFormatTable9

La constante par défaut est xlRangeAutoFormatClassic1.
Certaines de ces constantes ne seront peut-être pas disponibles,
en fonction de la langue sélectionnée ou installée (par exemple, le français).
__________________________________________________________________________________

isabelle

Bonjour, le code suivant:

Application.CommandBars("Worksheet Menu Bar").Controls("Format"). _
Controls("&Forme automatique...").Execute

Provoque une erreur 5 si je n'ai pas "initié" au moins une fois Excel
en effectuant la manip correspondante à la main, cad en clickant avec
ma souris sur le menu "Format" puis "Forme automatique".
Comment faire son "Initiation" via le code ?

Merci d'avance.



Avatar
manu
Bonjour Isabelle,

Tout d'abord merci de t'etre penchee sur mon message...
Helas, il me semble que l'instruction AutoFormat dont tu parles (que
je ne connaissais pas) est une méthode qui s'applique à une plage de
cellules.
Dans le cas qui m'intéresse la Selection concerne une Forme de type
msoShapeRectangle.

Détail:
L'utilisateur en clickant dessus accède au réglages "Couleurs et
traits" pour se faire j'ai créé la procédure suivante:

Public Sub FOND_Click()

Dim ShpFOND As Shape

ActiveSheet.Unprotect
Set ShpFOND = ActiveSheet.Shapes(Application.Caller)
ShpFOND.Select
Application.CommandBars("Worksheet Menu Bar").Controls("Format").
_
Controls("&Forme automatique...").Execute
ActiveSheet.Protect

End Sub

Et c'est la ligne Application.CommandBars........qui me pose pb
lorsque je n'ai pas "initié" Excel à ce menu avec la souris.
Avatar
isabelle
bonjour manu,

ajoute y un With,

With Selection
Application.CommandBars("Worksheet Menu Bar").Controls("Format").Controls("&Forme automatique...").Execute
End With

isabelle

Bonjour Isabelle,

Tout d'abord merci de t'etre penchee sur mon message...
Helas, il me semble que l'instruction AutoFormat dont tu parles (que
je ne connaissais pas) est une méthode qui s'applique à une plage de
cellules.
Dans le cas qui m'intéresse la Selection concerne une Forme de type
msoShapeRectangle.

Détail:
L'utilisateur en clickant dessus accède au réglages "Couleurs et
traits" pour se faire j'ai créé la procédure suivante:

Public Sub FOND_Click()

Dim ShpFOND As Shape

ActiveSheet.Unprotect
Set ShpFOND = ActiveSheet.Shapes(Application.Caller)
ShpFOND.Select
Application.CommandBars("Worksheet Menu Bar").Controls("Format").
_
Controls("&Forme automatique...").Execute
ActiveSheet.Protect

End Sub

Et c'est la ligne Application.CommandBars........qui me pose pb
lorsque je n'ai pas "initié" Excel à ce menu avec la souris.



Avatar
manu
Ma très chère Isabelle,
(J'ai l'impression de te connaitre après ces nombreux échanges de
mail ;o)

Ca n'est pas la solution, les 3 lignes de code ne fonctionnent que si
Excel a été "initié" au moins une fois manuellement à ce Controle.

Merci quand meme et bonne journée.