Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/05/2007, 10h33   #1
Candidat au titre de Membre du Club
 
Inscription : avril 2007
Messages : 93
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 93
Points : 11
Points : 11
Par défaut [VBA - W] ajout ligne dans un tableau

Bonjour
Je me suis évertuer à créer cette macro qui a pour but d'ajouter un ligne à un tableau et de pouvoir ajouter dans une colonne un champ qui reprend le n° du document (renseigné par l'utilisateur) et un système d'incrémentation.
Cette macro fonctionnait très bien mais plus depuis aujourd'hui et je ne me rappelle pas y avoir apporter de modifications.
Mon problème est donc de savoir s'il y a des erreurs dans cette macro et, celle-ci étant vraiment artisanalle, s'il y a possibilité de la simplifier en ayant le même résultat (celui qui fonctionne bien sûr).

J'y joins le code:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Private Sub CommandButton1_Click()
Dim objTable As Table
Set objTable = ThisDocument.Tables(4)
'Trouver le n° du tableau
Dim i As Integer
Dim lign As Integer
  Selection.MoveDown Unit:=wdLine, Count:=objTable.Rows.Count
ActiveDocument.Tables(4).Rows.Add
lign = objTable.Rows.Count
objTable.Rows(lign).Select
With Selection.Cells
    With .Shading
      .Texture = wdTextureNone
      .ForegroundPatternColor = wdColorAutomatic
      .BackgroundPatternColor = wdColorAutomatic
    End With
End With
objTable.Cell(lign, 1).Select
With Selection.Cells
  Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
  objTable.Cell(lign, 3).Range.Text = "-" & lign - 1
  Selection.HomeKey Unit:=wdLine
  Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "REF  Numero ", PreserveFormatting:=True
' Pour insérer un champ reprenant le n° du document
  Selection.EndKey Unit:=wdStory
End Sub
perophron est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/05/2007, 13h26   #2
Inactif
 
Avatar de ouskel'n'or
 
Inscription : février 2005
Messages : 12 466
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 12 466
Points : 11 930
Points : 11 930
Regarde , SilkyRoad indique une solution pour une colonne, pour une ligne, c'est pareil. Mais ça m'étonnerait fort que la solution ne soit pas dans la FAQ. Tu as regardé ?
ouskel'n'or est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/05/2007, 10h27   #3
Candidat au titre de Membre du Club
 
Inscription : avril 2007
Messages : 93
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 93
Points : 11
Points : 11
OK j'ai trouvé. Je laisse la macro qui fonctionne, ça peut servir.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Private Sub CommandButton1_Click()
Dim objTable As Table
Set objTable = ActiveDocument.Tables(2)
'Trouver le n° du tableau
Dim i As Integer
Dim lign As Integer
Dim g As Boolean
  Selection.MoveDown Unit:=wdLine, Count:=objTable.Rows.Count
ActiveDocument.Tables(2).Rows.Add
lign = objTable.Rows.Count
g = objTable.Rows(lign).Range.Font.Bold
objTable.Rows(lign).Select
With Selection.Cells
  If g = True Then
  Selection.Font.Bold = wdToggle
  End If
    With .Shading
      .Texture = wdTextureNone
      .ForegroundPatternColor = wdColorAutomatic
      .BackgroundPatternColor = wdColorAutomatic
    End With
End With
objTable.Cell(lign, 1).Select
With Selection.Cells
  Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
  objTable.Cell(lign, 3).Range.Text = "-" & lign - 1
  Selection.HomeKey Unit:=wdLine
  Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "REF  Numéro ", PreserveFormatting:=True
' Pour insérer un champ reprenant le n° du document
  Selection.EndKey Unit:=wdStory
  End
End Sub
perophron est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 19h14.


 
 
 
 
Partenaires

Hébergement Web