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 :confused:

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

Merci d'avance

Flag_of_Scotland.svg.png
 

BOISGONTIER

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

Bonsoir,

Pour créer un drapeau Français/Italien dans une cellule ou un champ
Si un texte est déjà présent dans la cellule ou le champ, il apparaît par transparence.

=drapeauFR(Champ;Transparence)
=drapeauIT(Champ;Transparence)

http://boisgontierjacques.free.fr/fichiers/Images/ConstructeurDrapeau.xls

Drapeau.gif

Sans titre.png


JB
 

Pièces jointes

  • ConstructeurDrapeau.xls
    69.5 KB · Affichages: 65
  • Sans titre.png
    Sans titre.png
    10.7 KB · Affichages: 63
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" :D

Cordialement

Edit: Fichier plus optimisé
 

Pièces jointes

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

Discussions similaires

Statistiques des forums

Discussions
312 225
Messages
2 086 411
Membres
103 201
dernier inscrit
centrale vet