IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Word Discussion :

[VBA - W] ajout ligne dans un tableau


Sujet :

VBA Word

  1. #1
    Nouveau membre du Club
    Inscrit en
    Avril 2007
    Messages
    93
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 93
    Points : 29
    Points
    29
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  2. #2
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Points : 15 546
    Points
    15 546
    Par défaut
    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é ?

  3. #3
    Nouveau membre du Club
    Inscrit en
    Avril 2007
    Messages
    93
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 93
    Points : 29
    Points
    29
    Par défaut
    OK j'ai trouvé. Je laisse la macro qui fonctionne, ça peut servir.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. VBA Probleme ajout ligne dans codemodule de feuille
    Par JYL74 dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 04/03/2010, 16h19
  2. Réponses: 9
    Dernier message: 14/04/2009, 16h20
  3. Réponses: 5
    Dernier message: 30/09/2008, 03h14
  4. [VBA-E] connaitre le nombre de ligne dans un tableau excel
    Par bigbarbe dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 13/04/2006, 10h03
  5. [VBA-E]insertion automatique d'une ligne dans un tableau
    Par janus82 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 06/04/2006, 15h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo