Mettre en gras plusieurs partie d'un texte dans une zone texte
Résolu/Fermé
bassmart
Messages postés
277
Date d'inscription
jeudi 19 février 2015
Statut
Membre
Dernière intervention
30 août 2022
-
26 avril 2016 à 21:33
bassmart Messages postés 277 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 30 août 2022 - 2 mai 2016 à 19:42
bassmart Messages postés 277 Date d'inscription jeudi 19 février 2015 Statut Membre Dernière intervention 30 août 2022 - 2 mai 2016 à 19:42
A voir également:
- Mettre en gras vba
- Ecrire en gras sur whatsapp - Guide
- Erreur 1004 vba ✓ - Forum VB / VBA
- Mettre en gras sur indesign ✓ - Forum InDesign
- Find vba - Astuces et Solutions
- L'indice n'appartient pas à la sélection vba - Forum VB / VBA
2 réponses
Frenchie83
Messages postés
2239
Date d'inscription
lundi 6 mai 2013
Statut
Membre
Dernière intervention
28 janvier 2023
335
27 avril 2016 à 07:45
27 avril 2016 à 07:45
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".
Mais vous pouvez remplacez les 2 paragraphes suivants
par
A tester
Cdlt
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
A tester
Cdlt
Frenchie83
Messages postés
2239
Date d'inscription
lundi 6 mai 2013
Statut
Membre
Dernière intervention
28 janvier 2023
335
29 avril 2016 à 10:36
29 avril 2016 à 10:36
Bonjour
Essayez ceci
Essayez ceci
Sub zone_texte()
Dim Phrase, PosSondage, PosElevation
Phrase = "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
PosSondage = InStr(1, Phrase, "SONDAGE", 1)
PosElevation = InStr(1, Phrase, "ÉLÉVATION T.N", 1)
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 = Phrase
.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:=PosSondage, 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:=PosElevation, Length:=14).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
End Sub
Cdlt
bassmart
Messages postés
277
Date d'inscription
jeudi 19 février 2015
Statut
Membre
Dernière intervention
30 août 2022
1
2 mai 2016 à 18:12
2 mai 2016 à 18:12
Merci beaucoup!
Ça fonctionne mais la mise en forme ne s'effectue pas pour la première lettre de chaque mots?
Ça fonctionne mais la mise en forme ne s'effectue pas pour la première lettre de chaque mots?
Frenchie83
Messages postés
2239
Date d'inscription
lundi 6 mai 2013
Statut
Membre
Dernière intervention
28 janvier 2023
335
>
bassmart
Messages postés
277
Date d'inscription
jeudi 19 février 2015
Statut
Membre
Dernière intervention
30 août 2022
2 mai 2016 à 18:53
2 mai 2016 à 18:53
Bonjour
ajouter -1 en bout de chaque ligne suivantes:
ce qui donne
ça devrait aller
Cdlt
ajouter -1 en bout de chaque ligne suivantes:
PosSondage = InStr(1, Phrase, "SONDAGE", 1)
PosElevation = InStr(1, Phrase, "ÉLÉVATION T.N", 1)
ce qui donne
PosSondage = InStr(1, Phrase, "SONDAGE", 1)-1
PosElevation = InStr(1, Phrase, "ÉLÉVATION T.1N", 1)-1
ça devrait aller
Cdlt
bassmart
Messages postés
277
Date d'inscription
jeudi 19 février 2015
Statut
Membre
Dernière intervention
30 août 2022
1
>
Frenchie83
Messages postés
2239
Date d'inscription
lundi 6 mai 2013
Statut
Membre
Dernière intervention
28 janvier 2023
2 mai 2016 à 19:42
2 mai 2016 à 19:42
Merci!
Ça fonctionne très bien en ajoutant -1 au bout de chacune des lignes!
Ça fonctionne très bien en ajoutant -1 au bout de chacune des lignes!
28 avril 2016 à 18:49
J'avais mal compris la fonction.
Merci!
Modifié par bassmart le 28/04/2016 à 21:08
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 SubMerci pour votre aide!