Macro pour insérer une zone de texte paramétrée et placée?

tempo

XLDnaute Nouveau
Bonsoir Le forum,:)
En tant que débutant, je cherche une macro qui insère une zone de texte avec des bordures et paramétrée pour justifier le texte que l'on tape à l'intérieur. Je souhaiterais également qu'elle soit placée en "G2:J15".

Il peut s'agir de cellules fusionnées avec bordures. L'important est qu'après enregistrement en tant que page web, le texte de ladite zone de texte (ou cellule fusionnée) soit facilement modifiable.

Merci de m'aider, je continue mes recherches dans ce sens et reste ouvert à toutes propositions.

Cordialement,
Geoffroy.
 

tempo

XLDnaute Nouveau
Re : Macro pour insérer une zone de texte paramétrée et placée?

Bonjour François,
Pour être plus clair, je me suis rabattu sur ce code obtenu en mode enregistrement de macro, faute de mieux:

Sub Cadre1()

'Fusionnement et insertion des bordures:

Range("G2:J15").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

Range("G2:J13").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge

Range("G14:J15").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge


Range("G2:J13").Select
With Selection
.HorizontalAlignment = xlJustify
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With

Range("G14:J15").Select
ActiveCell.FormulaR1C1 = "Prix : "
With ActiveCell.Characters(Start:=1, Length:=7).Font
.Name = "Arial"
.FontStyle = "Normal"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("G14:J15").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Gras"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("G2:J13").Select
ActiveCell.FormulaR1C1 = ""
Range("D32").Select


'Insertion du texte:
Texte1.Show

End Sub


C'est un peu lourd, mais bon.

J'utilise ensuite un Userform (Texte1) avec une TextBox (TextBox1) pour l'insertion du texte et une seconde TextBox (Prix1) pour l'insertion du prix:

Private Sub insert1_Click()
Range("G2:J13") = TextBox1
Range("G2:J13") = Application.WorksheetFunction.Substitute(TextBox1, vbCrLf, Chr(10))
Range("G14:J15") = Prix1
Texte1.Hide
Call enregistrer
Call fermer
End Sub

C'est vraiment du bricolage!
Mais après enregistrement en tant que page web, ça marche et il est au moins possible de modifier le prix, qui doit absolument pouvoir être modifiable manuellement lors de toute réouverture avec excel du fichier .htm créé.

Ce projet s'adresse à des utilisateurs novices, d'où cette procédure d'automatisation (voir pièces jointes).

Je reste ouvert à toute proposition de nettoyage des codes pour les rendre plus lisibles.

Cordialement,
Geoffroy.
 

Pièces jointes

  • procedure_Excel.jpg
    procedure_Excel.jpg
    34.1 KB · Affichages: 110
  • rendu_ds_IE.jpg
    rendu_ds_IE.jpg
    20.6 KB · Affichages: 97
  • autre_rendu_possible_ds_IE.JPG
    autre_rendu_possible_ds_IE.JPG
    46.4 KB · Affichages: 155
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 165
Messages
2 085 883
Membres
103 013
dernier inscrit
cicro