concaténation et retour à la ligne

Oldevi

XLDnaute Nouveau
Bonjour,

J'ai tapé le code suivant qui fonctionne bien, les box de mon userform viennent alimenter des shapes dans un slide powerpoint. Mon problème c'est que certaines de ces box sont vides. Lorsque la textbox est vide, j'aimerais ne pas avoir de retour à la ligne (vbCrLf).

Merci d'avance pour vos idées.



Private Sub ouvrirppt_Click()

S = langue.Value

Dim FichierPpt, pwpt, presppt
Set pwpt = CreateObject("PowerPoint.Application")
pwpt.Visible = True

Set presppt = pwpt.Presentations.Open(Filename:=ThisWorkbook.Path & "\" & "presentation.pptx")
pwpt.Visible = True

With presppt

Dim I As Byte

With .Slides(1).Shapes("Text Box 46").TextFrame.TextRange
.text = nom & vbCrLf & Box2 & Box3 & vbCrLf & "Tel.: " & Box4 & "Email: " & Box7
With .Characters(1, Len(nom)).Font
.Size = 15
.Bold = True
End With
End With
.Slides(1).Shapes("Text Box 11").TextFrame.TextRange.text = Box17
With .Slides(1).Shapes("Text Box 6").TextFrame.TextRange
.text = Box12 & " " & Label5.Caption & vbCrLf & Box13 & vbCrLf & Box14 & vbCrLf & Box15 & vbCrLf & Box16 _
& vbCrLf & Box8 & vbCrLf & Box9 & vbCrLf & Box10 & vbCrLf & Box11 _
& vbCrLf & Box18 & vbCrLf & Box19 & vbCrLf & Box20 & vbCrLf & Box21
With .Characters(1, Len(Box12) + Len(Label5.Caption) + 1).Font
.Size = 10
.Bold = True
End With
With .Characters(Len(Box12) + Len(Label5.Caption) + 1, Len(Box13) + 1).Font
.Size = 9
.Bold = False
End With
With .Paragraphs(2)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(3)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(4)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
End With
End With

End Sub
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Bonsoir Oldevi,

Par exemple après la ligne de code en bleu on peut ajouter celle en rouge :

.Text = nom & vbCrLf & Box2 & Box3 & vbCrLf & "Tel.: " & Box4 & "Email: " & Box7
If Replace(.Text, vbCrLf, "") = "" Then .Text = ""

A+
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Bonjour le forum,

J'ai écrit n'importe quoi hier soir !

Au lieu de :

Code:
.Text = nom & vbCrLf & Box2 & Box3 & vbCrLf & "Tel.: " & Box4 & "Email: " & Box7
écrire :

Code:
.Text = nom & IIf(Box2 & Box3 = "", "", vbCrLf & Box2 & Box3) & IIf(Box4 = "", "", vbCrLf & "Tel.: " & Box4) & IIf(Box7 = "", "", vbCrLf & "Email: " & Box7)
Même principe pour les autres Shapes, utiliser IIf.

A+
 

Oldevi

XLDnaute Nouveau
Re : concaténation et retour à la ligne

Bonjour Job75


Excellent, c'est exactement ce que je voulais, je vais tester ca tout de suite. Merci beaucoup !

Comme tu as l'air assez calé, j'ai également un problème avec le format des paragraphes. Pour l'instant j'arrive a mettre un format "bullet" pour les numéros de paragraphes (ici 2,3 et 4). Seulement, les numéros seront différents d'un formulaire à l'autre (suivant qu'une ou plusieurs textbox sont vides). Y a t'il un moyen d'affecter le format de paragraphe à la textbox plutôt qu'au numéro de paragraphe ?

Merci encore et bonne journée.
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Re,

Pas compris pourquoi la numérotation des paragraphes commence à 2 mais enfin...

Comme le format est toujours le même - ppBulletUnnumbered - pourquoi ne pas mettre :

Code:
On Error Resume Next
avant la ligne :

Code:
With .Paragraphs(2)
A+
 

Oldevi

XLDnaute Nouveau
Re : concaténation et retour à la ligne

Salut,

Le paragraphe commence à 2 car le premier paragraphe ne nécessite pas d'etre modifié. La premiere ligne sera en bold, les lignes 2 à 4 seront en bullet suivant que les textbox sont remplies ou non. La ligne suivante sera en bold. Etc. Donc plusieurs formats différents.

Une idée ?
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Re,

Utilisez la variable I pour compter les Shapes non vides et adaptez ce code :

Code:
With presppt
 
  Dim I As Byte

  With .Slides(1).Shapes("Text Box 46").TextFrame.TextRange
   .Text = ... 'à compléter
   If .Text <> "" Then I = I + 1
   '---
  End With

  .Slides(1).Shapes("Text Box 11").TextFrame.TextRange.Text = Box17
  If Box17 <> "" Then I = I + 1

  With .Slides(1).Shapes("Text Box 6").TextFrame.TextRange
   .Text = ...'à compléter
   If .Text <> "" Then I = I + 1
   '---
  End With

  For I = 1 To I
   .Paragraphs(I + 1).ParagraphFormat.Bullet.Type = ppBulletUnnumbered
  Next
  
End With
A+
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Re,

Encore une fois j'étais à côté de la plaque, les paragraphes à étudier concernent la 3ème Shape !

Et ils sont déterminés par Box13 Box14 Box15.

Donc voyez en remplaçant :

Code:
With .Paragraphs(2)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(3)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(4)
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
par :

Code:
I = -(Box13 <> "") - (Box14 <> "") - (Box15 <> "")
For I = 1 To I
.Paragraphs(I + 1).ParagraphFormat.Bullet.Type = ppBulletUnnumbered
Next
Se rappeler que True se convertit en -1.

A+
 

Oldevi

XLDnaute Nouveau
Re : concaténation et retour à la ligne

Merci job75, IIf pour le retour à la ligne marche parfaitement.

Pour mon autre problème, en fait c'est au sein de la même shape que j'ai plusieurs polices et formats différents. Ce sont mes textbox de mon userform qui viennent alimenter la même shape dans ma présentation ppt. Ainsi j'ai:

With .Paragraphs(1)
.Font.Size = 10
.Font.Bold = True
End With
With .Paragraphs(2)
.Font.Size = 9
.Font.Bold = False
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(3)
.Font.Size = 9
.Font.Bold = False
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
With .Paragraphs(4)
.Font.Size = 10
.Font.Bold = True
End With

Cependant il peut arriver que si ma textbox dans mon userform est vide, mes lignes de paragraphes sont décalés et le paragraph(3) devrait avoir le format affecté au paragraphe(4).

Bonne soirée.
 

job75

XLDnaute Barbatruc
Re : concaténation et retour à la ligne

Re,

L'ennui c'est que je ne peux pas tester ce que je vous propose.

Essayez maintenant ceci :

Code:
With .Paragraphs(1)
  .Font.Size = 10
  .Font.Bold = True
End With
If Box13 <> "" Then
  With .Paragraphs(2)
    .Font.Size = 9
    .Font.Bold = False
    .ParagraphFormat.Bullet.Type = ppBulletUnnumbered
  End With
End If
If Box14 <> "" Then
  With .Paragraphs(2 - (Box13 <> ""))
    .Font.Size = 9
    .Font.Bold = False
    .ParagraphFormat.Bullet.Type = ppBulletUnnumbered
  End With
End If
If Box15 <> "" Then
  With .Paragraphs(2 - (Box13 <> "") - (Box14 <> ""))
    .Font.Size = 10
    .Font.Bold = True
  End With
End If
Edit : êtes vous sûr des formats du dernier paragraphe ?

A+
 
Dernière édition:

Oldevi

XLDnaute Nouveau
Re : concaténation et retour à la ligne

Merci infiniment,

Je vais tester ça tout à l'heure et je vous tiens au courant.

Le dernier paragraphe n'est pas vraiment mon dernier, j'ai simplifié pour faciliter la compréhension du code. En gros je vais avoir qqch du type:

Bold
- Bullet
- Bullet

Bold
- Bullet
- Bullet

Bonne journée.
 

Oldevi

XLDnaute Nouveau
Re : concaténation et retour à la ligne

Pour info le code gagnant:


With .Paragraphs(1)
.Font.Size = 10
.Font.Bold = True
End With
I = -(Box13 <> "") - (Box14 <> "") - (Box15 <> "") - (Box16 <> "")
J = -(Box8 <> "") - (Box9 <> "") - (Box10 <> "") - (Box11 <> "")
K = -(Box18 <> "") - (Box19 <> "") - (Box20 <> "") - (Box21 <> "")
For I = 1 To I
With .Paragraphs(I + 1)
.Font.Size = 9
.Font.Bold = False
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
Next
With .Paragraphs(I + 2)
.Font.Size = 10
.Font.Bold = True
End With
For J = 1 To J
With .Paragraphs(I + J + 2)
.Font.Size = 9
.Font.Bold = False
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
Next
With .Paragraphs(I + J + 3)
.Font.Size = 10
.Font.Bold = True
End With
For K = 1 To K
With .Paragraphs(I + J + K + 3)
.Font.Size = 9
.Font.Bold = False
.ParagraphFormat.Bullet.Type = ppBulletUnnumbered
End With
Next
 

Discussions similaires

Statistiques des forums

Discussions
312 332
Messages
2 087 361
Membres
103 530
dernier inscrit
Chess01