En cherchant un peu j'ai trouvé une macro pour insérer une zone de texte automatiquement sur une feuille. J'ai réussi à mettre une partie de mon texte en gras, mais je veux mettre aussi les mots "SITE:", "SONDAGE:" et ÉLÉVATION T.N:" en gras.
Mais voilà, je n'y arrive pas!!
Voici mon code:
Sub zone_texte()
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 140, 10, _
500, 70).Select
With selection
.Name = "Ma_zone"
.ShapeRange.Fill.Visible = msoTrue
.ShapeRange.Fill.Solid
.ShapeRange.Fill.Transparency = 0#
.ShapeRange.Line.Weight = 0.75
.ShapeRange.Line.DashStyle = msoLineSolid
.ShapeRange.Line.Style = msoLineSingle
.ShapeRange.Line.Transparency = 0#
.ShapeRange.Line.Visible = msoTrue
.ShapeRange.Line.ForeColor.SchemeColor = 64
.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
.Characters.Text = "SUIVI PIÉZOMÉTRIQUE" & vbCrLf & vbCr & "SITE: " & UserForm2.TextBox1 & Space(45) & "SONDAGE: " & UserForm2.TextBox2 & Space(45) & "ÉLÉVATION T.N: "
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
With selection.Characters(Start:=1, Length:=20).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = xlAutomatic
End With
With selection.Characters(Start:=21, Length:=22).Font' Ici ça ne fonctionne pas le mots "Site" et tout ce qui suit est en gras
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
End Sub
Bonjour
Length=indique le nombre de caractères retenus à partir du premier indiqué par la valeur de "Start". Dans votre cas, vous prenez 22 caractères à partir du 21ème. Remplacez Length:=22 par Length:=4 pour les 4 caractères de "Site".
With selection.Characters(Start:=21, Length:=4).Font
Mais vous pouvez remplacez les 2 paragraphes suivants
With selection.Characters(Start:=1, Length:=20).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = xlAutomatic
End With
With selection.Characters(Start:=21, Length:=22).Font' Ici ça ne fonctionne pas le mots "Site" et tout ce qui suit est en gras
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
par
With selection.Characters(Start:=1, Length:=25).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = xlAutomatic
End With
Le problème c'est que j'insère du texte avec des textbox via un userform et les mots insérés ne sont pas toujours de la même longueur. Donc au final, mes titres (SONDAGE et ÉLÉVATION T.N ne sont pas toujours en gras comme voulu.
Il y a t'il un autre solution?
Voici mon code complet:
Sub zone_texte()
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 10, _
600, 70).Select
With selection
.Name = "Ma_zone"
.ShapeRange.Fill.Visible = msoTrue
.ShapeRange.Fill.Solid
.ShapeRange.Fill.Transparency = 0#
.ShapeRange.Line.Weight = 0.75
.ShapeRange.Line.DashStyle = msoLineSolid
.ShapeRange.Line.Style = msoLineSingle
.ShapeRange.Line.Transparency = 0#
.ShapeRange.Line.Visible = msoTrue
.ShapeRange.Line.ForeColor.SchemeColor = 64
.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
.Characters.Text = "MINISTÈRE DES TRANSPORT - SUIVI PIÉZOMÉTRIQUE" & vbCrLf & vbCr & "SITE: " & UserForm2.TextBox1 & Space(45) & "SONDAGE: " & UserForm2.TextBox2 & Space(45) & "ÉLÉVATION T.N: " & UserForm2.TextBox3
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
With selection.Characters(Start:=1, Length:=45).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 14
.ColorIndex = xlAutomatic
End With
With selection.Characters(Start:=46, Length:=7).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
With selection.Characters(Start:=103, Length:=8).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
With selection.Characters(Start:=161, Length:=14).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
End Sub
J'avais mal compris la fonction.
Merci!
Le problème c'est que j'insère du texte avec des textbox via un userform et les mots insérés ne sont pas toujours de la même longueur. Donc au final, mes titres (SONDAGE et ÉLÉVATION T.N ne sont pas toujours en gras comme voulu.
Il y a t'il un autre solution?
Voici mon code complet:
Merci pour votre aide!