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.