Problème pour la création de tableau

Résolu
neo1602brice Messages postés 77 Date d'inscription dimanche 27 avril 2003 Statut Membre Dernière intervention 10 juillet 2009 - 30 mai 2008 à 12:14
neo1602brice Messages postés 77 Date d'inscription dimanche 27 avril 2003 Statut Membre Dernière intervention 10 juillet 2009 - 31 mai 2008 à 00:46
Salut à tous c'est encore moi
Je tiens d'abord à remercier encore bigfish_le vrai pour son aide(voir ici) mais lorsque je lance mon programme il m'affiche l'erreur suivante
"Erreur d'exécution 91: Variable d'objet ou bloc with non défini"

Voici mes procédures:
Private Sub Command1_Click()
    Call CreeTableau(5, 2)
End Sub

Public Sub CreeTableau(NbLignes As Integer, NbColonnes As Integer)
    Dim wd As Word.Application
    Set wd = CreateObject("word.application")
    With wd
        .Documents.Add
        .Visible = True
        .ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=NbLignes, NumColumns:=NbColonnes
    End With
End Sub

Il me fait donc mon erreur sur la ligne en rouge !!!!
Je suis perdu

merci d'avance à tous !

2 réponses

bigfish_le vrai Messages postés 1835 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 20 novembre 2013 15
30 mai 2008 à 17:01
Salut,

merci pour les remerciments

je te donne 2 methodes, a toi de voir, mais j'ai pas d'explication j'ai juste utilisé l'aide

Sub CreeTableau(NbLignes As Long, NbColonnes As Long)
    Dim wd As Object, myRange As Object
    Set wd = CreateObject("word.application")
    With wd
        .Documents.Add
        .Visible = True
        Set myRange = .ActiveDocument.Range(0, 0)
        .ActiveDocument.Tables.Add Range:=myRange, NumRows:=NbLignes, NumColumns:=NbColonnes
    End With
End Sub

Sub CreeTableau(NbLignes As Long, NbColonnes As Long)
    Dim wd As Object, myTable As Object, myRange As Object
    Set wd = CreateObject("word.application")
    With wd
        .Documents.Add
        .Visible = True
        Set myRange = .ActiveDocument.Range(0, 0)
        Set myTable = .ActiveDocument.Tables.Add(Range:=myRange, NumRows:=NbLignes, NumColumns:=NbColonnes)
    End With
End Sub

et j'aime toujours pas word

remarque : essai d'etre le plus generale possible c'est a dire de declare la variable wd en object et pas en Word.Application et aussi de ne pas utilisé de format predefinit specifique a word ou tout autre specificité. cela permetra a ton projet d'etre facilement exportable sans avoir a utilisé la reference microsoft word.

y a rien a faire j'aime pas word

et puis tien je vais etre gentil voici un bout de l'aide :
------------------------------------------------------------------------------------------------------------------
This example adds a blank table with three rows and four columns at the
beginning of the active document.
Set myRange = ActiveDocument.Range(0, 0)
ActiveDocument.Tables. Add  Range: =myRange, NumRows:= 3, NumColumns:=4


This example adds a new, blank table with six rows and ten columns at the end
of the active document

Set MyRange = ActiveDocument.Content
MyRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables. Add  Range: =MyRange, NumRows:=6, _
    NumColumns:=10


This example adds a table with three rows and five columns to a new document
and then inserts data into each cell in the table.

Sub NewTable()
    Dim docNew As Document
    Dim tblNew As Table
    Dim intX As Integer
    Dim intY As Integer

    Set docNew = Documents.Add
    Set tblNew = docNew.Tables.Add(Selection.Range, 3, 5)
    With tblNew
    For intX = 1 To 3
        For intY = 1 To 5
            .Cell(intX, intY).Range.InsertAfter "Cell: R" & intX & ", C" & intY
        Next intY
    Next intX
    .Columns.AutoFit
    End With
End Sub
-----------------------------------------------------------------------------------------


non decidement word ça passe pas

A+
3
neo1602brice Messages postés 77 Date d'inscription dimanche 27 avril 2003 Statut Membre Dernière intervention 10 juillet 2009
31 mai 2008 à 00:46
OOOOUUUUIIII maintenant ca marche, franchement je ne te remercierai jamais assez bigfish_le_vrai
Word (:d)

Pour te rassurer moi non plus j'aime plus word depuis que j'ai découvert OO

[auteur/BIGFISHLEVRAI/510670.aspx ]
0
Rejoignez-nous