Macro

Résolu
sonice -  
 sonice -
Bonjour,

J'ai une petite question pour une macro toute simple.
J'ai un bouton de commande (creer par "formulaires") sur ma feuille 1 et en appuyant dessus je veux que la macro se réalise dans la feuille 2, une fois que c'est fait je rappuie pour que la macro s'execute dans la feuille 3,...
En gardant toujours le bouton sur la 1ere feuille
Si qqun pouvait m'aider ce serait super.

Merci
Configuration: Windows XP
Internet Explorer 7.0

1 réponse

  1. melanie1324
     
    Bonjour,

    Je ne comprends pas exactement ce que tu veux mais je vais te donner une solution et à toi de me dire si elle te convient ou non.

    Tu peux jouer soit avec des variables soit avec des boites de dialogue.

    Pour les variables :
    C'est si tu veux que lorsque tu cliques sur le bouton, elle agisse sur la première feuille puis sur la seconde puis sur la troisième etc.. mets ce programme

    Au début de ta macro
    a=1
    do while a > X (X étant ton nombre de feuilles)
    if a=1then
    sheets(" ").select (dans la parenthèse et entourée de guillemets le nom de ta feuille 1)
    end if
    if a =2 then
    sheets(" ").select (le nom de la feuille 2)
    end if

    ta macro

    en fin de macro
    a=a+1
    loop
    end sub

    Le soucis, c'est que si tu changes le nom des feuilles, faut changer ton programme

    Autre solution : boïte de dialogue
    a= "Voulez-vous que cette macro agisse sur la feuille1"
    b=msgbox(a,vbyesno)
    if b=1 then (1= si l'utilisateur à cliquer sur oui)
    sheets("feuil1").select
    else
    a="Voulez-vous que cette macro agisse sur la feuille2?"
    b=msgbox(a,vbyesno)
    if b= 1 then
    sheets ("feuil2").select
    end if
    end if

    Comme pour le 1er, si tu changes le nom des feuilles, il faut changer ton programme.

    sinon dernière solution
    sheets("Feuil1").select
    a = activesheet.name
    (tu laisses feuil1)
    b="Voulez-Vous que cette macro agisse sur la feuille " & a & "?"
    c=msgbox(b, vbyesno)
    if c = 1
    sheets(a).select
    end if

    autre

    a= "Sur quelle feuille voulez-vous que cette macro agisse?"
    b=Inputbox (a)
    sheets(b).select

    mais la faut que l'utilisateur ne se trompe pas dans le nom de la feuille.

    Bon courage
    0
    1. sonice
       
      Ok merci! Je vais essayer les deux premières solutions, ce sont celles qui ont l'air de plus se rappocher de ce que je veux, en particulier la première. Je te tiens au courant. Merci de ton aide
      0
    2. sonice
       
      Bonjour,

      J'ai essayé tes formules, finalement celle qui me correspond est la dernière. Elle est plu simple et l'utilisateur n'aura qu'à rentrer le nom de la feuille où la macro doit être effectuée. Mais j'ai un problème lorsque j'execute la macro avec ta formule :
      Erreur d'exécution 9 : l'indice n'appartient pas à la selection

      Voici ma macro

      Sub Adhérent()
      '
      ' Adhérent Macro
      ' Macro enregistrée le 03/04/2008 par moi
      '

      '
      With Selection.Font
      .Name = "Arial"
      .Size = 14
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Selection.Font.Bold = True
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      ActiveCell.FormulaR1C1 = "NOM Prénom"
      Range("B3").Select
      With Selection.Font
      .Name = "Arial"
      .Size = 12
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Selection.Font.Bold = True
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      ActiveCell.FormulaR1C1 = "Secteur"
      Range("A10,A12,A14,A19,A21,A30").Select
      Range("A30").Activate
      ActiveWindow.SmallScroll Down:=6
      Range("A10,A12,A14,A19,A21,A30,A41").Select
      Range("A41").Activate
      With Selection.Font
      .Name = "Arial"
      .Size = 12
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      With Selection.Font
      .Name = "Arial"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Selection.Font.Bold = True
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlTop
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      ActiveWindow.SmallScroll Down:=-21
      Range("A10").Select
      ActiveCell.FormulaR1C1 = "adresse"
      Range("A10").Select
      ActiveCell.FormulaR1C1 = "Adresse"
      Range("A12").Select
      ActiveCell.FormulaR1C1 = "N°tél"
      Range("A14").Select
      ActiveCell.FormulaR1C1 = "Courriel"
      Range("A19").Select
      ActiveCell.FormulaR1C1 = "1ère adhésion"
      With ActiveCell.Characters(Start:=1, Length:=1).Font
      .Name = "Arial"
      .FontStyle = "Gras"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      With ActiveCell.Characters(Start:=2, Length:=3).Font
      .Name = "Arial"
      .FontStyle = "Gras"
      .Size = 11
      .Strikethrough = False
      .Superscript = True
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      With ActiveCell.Characters(Start:=5, Length:=9).Font
      .Name = "Arial"
      .FontStyle = "Gras"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Range("A21").Select
      ActiveCell.FormulaR1C1 = "Raison"
      Range("A30").Select
      ActiveCell.FormulaR1C1 = "Année"
      Range("A41").Select
      ActiveCell.FormulaR1C1 = "Observations"
      Columns("B:B").Select
      Range("B14").Activate
      Columns("A:A").EntireColumn.AutoFit
      ActiveWindow.SmallScroll Down:=-18
      Range("B10").Select
      Columns("B:B").ColumnWidth = 40
      Range("B10,B21").Select
      Range("B21").Activate
      ActiveWindow.SmallScroll Down:=18
      Range("B10,B21,B41").Select
      Range("B41").Activate
      With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlBottom
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      ActiveWindow.SmallScroll Down:=-15
      Range("B10,B21,B41,B19,B14,B12").Select
      Range("B12").Activate
      With Selection.Font
      .Name = "Arial"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      With Selection
      .HorizontalAlignment = xlLeft
      .VerticalAlignment = xlBottom
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      ActiveWindow.SmallScroll Down:=15
      Range("B30").Select
      With Selection.Font
      .Name = "Arial"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Selection.Font.Bold = True
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      Range("C28:D28").Select
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      With Selection.Font
      .Name = "Arial"
      .Size = 11
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      End With
      Range("C28").Select
      ActiveCell.FormulaR1C1 = "Chèque"
      Range("D28").Select
      ActiveCell.FormulaR1C1 = "Espèce"
      Range("C30:D30").Select
      Selection.NumberFormat = "#,##0 $"
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      Range("B41").Select
      ActiveWindow.SmallScroll Down:=-27
      Range("B1").Select
      End Sub



      Je sais pas si ca pourra t'aider.
      Merci de ta réponse
      0