Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Fonction VBA pour dessiner un drapeau écossais

Pino12

XLDnaute Junior
Bonjour le forum,

Je dois dessiner un drapeau écossais à l'aide d'une fonction pour mon cours de VBA. Seulement cela implique de créer des diagonales et de colorier uniquement la moitié d'une cellule. Après avoir chercher sur internet je n'ai toujours pas trouver de solution

Si quelqu'un à une idée sur le fonctionnement d'une telle fonction, je suis preneur !

Merci d'avance

 

Pino12

XLDnaute Junior
Re : Fonction VBA pour dessiner un drapeau écossais

Merci beaucoup Pierre !

Tu pourrais m'expliquer cette phrase s'il te plait ? Je comprends bien le reste de la macro sinon
For Each sh In ActiveSheet.Shapes
sh.Delete
 

BOISGONTIER

XLDnaute Barbatruc
Repose en paix

Pièces jointes

  • ConstructeurDrapeau.xls
    69.5 KB · Affichages: 65
  • Sans titre.png
    10.7 KB · Affichages: 64
Dernière édition:

job75

XLDnaute Barbatruc
Re : Fonction VBA pour dessiner un drapeau écossais

Bonjour Pino12, tatiak, JB,

Voyez le fichier joint et cette macro :

Code:
Sub DrapeauEcossais(cel As Range)
Dim x, y, w, h, e

With cel
  x = .Left: y = .Top
  w = .Width: h = .Height
  e = Application.Min(w, h) / 8 'coefficient à adapter
End With

ActiveSheet.DrawingObjects.Delete

ActiveSheet.Shapes.AddShape msoShapeIsoscelesTriangle, x + e, y + h / 2 + e, w - 2 * e, h / 2 - e

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x + e, y, w - 2 * e, h / 2 - e)
  .Rotation = 180
End With

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, 0, 0)
  .Rotation = 90
  .Left = x + w / 2 - e: .Top = y + e
  .Width = h - 2 * e: .Height = w / 2 - e
End With

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, 0, 0)
  .Rotation = -90
  .Left = x + w / 2 + e: .Top = y + h - e
  .Width = h - 2 * e: .Height = w / 2 - e
End With

End Sub
A+
 

Pièces jointes

  • Drapeau écossais(1).xlsm
    22.3 KB · Affichages: 46
Dernière édition:

job75

XLDnaute Barbatruc
Re : Fonction VBA pour dessiner un drapeau écossais

Re,

Si l'on veut définir la couleur il suffit d'ajouter un argument à la macro :

Code:
Sub DrapeauEcossais(cel As Range, couleur As Range)
Dim x, y, w, h, e

With cel
  x = .Left: y = .Top
  w = .Width: h = .Height
  e = Application.Min(w, h) / 8 'coefficient à adapter
End With

ActiveSheet.DrawingObjects.Delete

ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x + e, y + h / 2 + e, w - 2 * e, h / 2 - e) _
  .Fill.ForeColor.RGB = couleur.Interior.Color

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x + e, y, w - 2 * e, h / 2 - e)
  .Rotation = 180
  .Fill.ForeColor.RGB = couleur.Interior.Color
End With

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, 0, 0)
  .Rotation = 90
  .Left = x + w / 2 - e: .Top = y + e
  .Width = h - 2 * e: .Height = w / 2 - e
  .Fill.ForeColor.RGB = couleur.Interior.Color
End With

With ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, 0, 0)
  .Rotation = -90
  .Left = x + w / 2 + e: .Top = y + h - e
  .Width = h - 2 * e: .Height = w / 2 - e
  .Fill.ForeColor.RGB = couleur.Interior.Color
End With

End Sub
Fichier (2).

A+
 

Pièces jointes

  • Drapeau écossais(2).xlsm
    22.4 KB · Affichages: 48

Efgé

XLDnaute Barbatruc
Re : Fonction VBA pour dessiner un drapeau écossais

Bonjour

Ne réponds pas à la question, mais pourra être utile si il y a un "cours de graph"

Cordialement

Edit: Fichier plus optimisé
 

Pièces jointes

  • écossais.xlsx
    14 KB · Affichages: 57
Dernière édition:

Discussions similaires

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…