Word : Sélectionner une table à l'intérieur d'une table

Fermé
ProgrammerWho - Modifié par Whismeril le 31/07/2015 à 15:30
Bonjour,

J'ai un tableau créé avec un Bookmark dans mon document, créé à partir de VBA dans une première étape
Sub Create_DataBlock()
    Dim newTable As Table
    
    Dim BookmarkName As String
    Dim Title As String
    
    'We put the title of the table here, and the bookmark name
    Title = "Title"
    BookmarkName = "Bookmarkname"
    
    'We put a new line at Selection position
    Selection.TypeParagraph
    
    Set newTable = ActiveDocument.Tables.Add(Selection.Range, 3, 1, wdWord9TableBehavior, wdAutoFitWindow)
    
 'Un peu de design
 '...
    
    'Adding the bookmark
    newTable.Cell(1, 1).Select
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:=BookmarkName
    End With
End Sub


A l'intérieur de la case(2,1), je veut insérer une table que je récupérerais à partir de mon bookmark, mais je n'y arrive actuellement pas. (cette table est ajoutée à la main après la création de la table parent par la macro)
La méthode que j'utilise actuellement :
    Selection.GoTo What:=wdGoToBookmark, Name:="Bookmarkname"
    Selection.MoveDown
    Set table= Selection.Tables(1)

Ce code récupère toute la table créée par la macro précédente.
J'ai essayé
    'test 1
    Selection.GoTo What:=wdGoToBookmark, Name:="Bookmarkname"
    Selection.MoveDown
    Selection.Tables(1).Cell(2,1).select
    set table = selection.tables(1)

    'test 2
    Selection.GoTo What:=wdGoToBookmark, Name:="Bookmarkname"
    Selection.MoveDown
    Selection.MoveRight
    set table = selection.tables(1)

    'test 3
    Selection.GoTo What:=wdGoToBookmark, Name:="Bookmarkname"
    Selection.MoveDown
    set table = Selection.Tables(1).Cell(2,1).Range.Tables(1)


Aucun des codes auquel j'ai pensé ne me renvoie la table que je veut, tous me renvoient la table parent.

Quelqu'un pourrait-il m'indiquer comment faire s'il vous plait?

Merci d'avance!

Cordialement,
ProgrammerWho

EDIT: Précision du langage dans la coloration syntaxique.