Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 2021
-
13 mai 2009 à 11:38
320C
Messages postés93Date d'inscriptiondimanche 24 avril 2011StatutMembreDernière intervention15 janvier 2014
-
9 janv. 2013 à 11:22
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
Salut à Tous.
Merci pour la solution (je n'ai testé que celle de garoui pour le moment).
J'ai un petit problème et j'espère avoir votre aide : en fait j'ai les cellules de la première ligne fusionnées par triplets dans mon MSFlexGrid (C'est à dire que chaque trois cellules forment une seule). Qu'est ce que je dois ajouter au code pour avoir le même résultat en Word ?
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 10 janv. 2012 à 07:24
menu Projet > Reference > Microsoft Word
320C
Messages postés93Date d'inscriptiondimanche 24 avril 2011StatutMembreDernière intervention15 janvier 2014 9 janv. 2012 à 23:51
Salut à tous!
SVP, aidez moi, ... j'utilise VB 6.0 édition professionnel, mais pour essayer de declarer le variable word???; cela ne marche pas
Càd exemple:
dim oWord as Word.application
Ceci ne mais donne pas l'oportunite de regenere Word dans la liste de proprété qui sorte et ci je vais faire la mailin à copier, le programme affiche une erreur sur cette déclaration.
Merci à tous pour votre contrbibution...
cres12
Messages postés5Date d'inscriptionlundi 24 octobre 2005StatutMembreDernière intervention20 juillet 2012 28 oct. 2011 à 11:06
Excellent pour le code, cependant j'aimerais ajouter 2 tableaux dans le fichhier word comment faire?
cs_goc
Messages postés19Date d'inscriptionsamedi 25 octobre 2003StatutMembreDernière intervention21 avril 2011 20 oct. 2010 à 13:45
Renfield
peu etre un peu rapide ta modif du prog
voila une version qui "fonctionne" :-))
Public Sub AppendGridToWordDoc(ByRef voGrid As MSFlexGrid, Optional ByRef voDoc As Word.Document)
Dim oWord As Word.Application
Dim nRow As Integer
Dim nCol As Integer
Dim sBuffer As String
Dim stemp As String
If Not Nothing Is voGrid Then
For nRow = 0 To voGrid.Rows - 1
For nCol = 0 To voGrid.Cols - 1
stemp = voGrid.TextMatrix(nRow, nCol)
If nCol = voGrid.Cols - 1 Then
stemp = stemp & vbCrLf
Else
stemp = stemp & vbTab
End If
sBuffer = sBuffer + stemp
Next nCol
Next nRow
If Nothing Is voDoc Then
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Nothing Is oWord Then
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
End If
Set voDoc = oWord.Documents.Add
End If
With voDoc.Bookmarks("\EndOfDoc").Range
.text = sBuffer
.ConvertToTable vbTab, Format:=wdTableFormatColorful2 '9
End With
End If
End Sub
cs_drissou
Messages postés160Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention14 janvier 2009 15 mai 2009 à 10:49
Merci garoui et Renfield (pour l'optimisation)
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 13 mai 2009 à 11:47
un peu de nettoyage plus tard:
Private Sub AppendGridToWordDoc(ByRef voGrid As MsFlexgrid, Optional ByRef voDoc As Word.Document)
Dim oWord As Word.Application
Dim nRow As Integer
Dim nCol As Integer
Dim sBuffer As String
If Not Nothing Is voGrid Then
For nRow = 0 To voGrid.Rows - 1
For nCol = 0 To voGrid.Cols - 1
sBuffer = sTemp & voGrid.TextMatrix(row, col)
If nCol = voGrid.Cols - 1 Then
sBuffer = sBuffer & vbCrLf
Else
sBuffer = sBuffer & vbTab
End If
Next nCol
Next nRow
If Nothing Is voDoc Then
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Nothing Is oWord Then
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
End If
Set voDoc = oWord.Documents.Add
End If
With voDoc.Bookmarks("\EndOfDoc").Range
.Text = sBuffer
.ConvertToTable vbTab, Format:=wdTableFormatColorful2 '9
End With
End If
End Sub
ici, on peux fournir une grille en parametre, ainsi qu'un document word auquel on souhaite ajouter notre tableau (l'ajout se fait systématiquement à la fin du document)
on utilise également une petite astuce (GetObject) permettant de se raccrocher à une instance Word existante (plus rapide: pas besoin de CreateObject)
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 13 mai 2009 à 11:38
pourquoi passes tu par la création du tableau arr ?
plus utile sous la forme d'une fonction réutilisable.
9 janv. 2013 à 11:22
30 déc. 2012 à 17:04
Merci pour la solution (je n'ai testé que celle de garoui pour le moment).
J'ai un petit problème et j'espère avoir votre aide : en fait j'ai les cellules de la première ligne fusionnées par triplets dans mon MSFlexGrid (C'est à dire que chaque trois cellules forment une seule). Qu'est ce que je dois ajouter au code pour avoir le même résultat en Word ?
10 janv. 2012 à 07:24
9 janv. 2012 à 23:51
SVP, aidez moi, ... j'utilise VB 6.0 édition professionnel, mais pour essayer de declarer le variable word???; cela ne marche pas
Càd exemple:
dim oWord as Word.application
Ceci ne mais donne pas l'oportunite de regenere Word dans la liste de proprété qui sorte et ci je vais faire la mailin à copier, le programme affiche une erreur sur cette déclaration.
Merci à tous pour votre contrbibution...
28 oct. 2011 à 11:06
20 oct. 2010 à 13:45
peu etre un peu rapide ta modif du prog
voila une version qui "fonctionne" :-))
Public Sub AppendGridToWordDoc(ByRef voGrid As MSFlexGrid, Optional ByRef voDoc As Word.Document)
Dim oWord As Word.Application
Dim nRow As Integer
Dim nCol As Integer
Dim sBuffer As String
Dim stemp As String
If Not Nothing Is voGrid Then
For nRow = 0 To voGrid.Rows - 1
For nCol = 0 To voGrid.Cols - 1
stemp = voGrid.TextMatrix(nRow, nCol)
If nCol = voGrid.Cols - 1 Then
stemp = stemp & vbCrLf
Else
stemp = stemp & vbTab
End If
sBuffer = sBuffer + stemp
Next nCol
Next nRow
If Nothing Is voDoc Then
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Nothing Is oWord Then
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
End If
Set voDoc = oWord.Documents.Add
End If
With voDoc.Bookmarks("\EndOfDoc").Range
.text = sBuffer
.ConvertToTable vbTab, Format:=wdTableFormatColorful2 '9
End With
End If
End Sub
15 mai 2009 à 10:49
13 mai 2009 à 11:47
Private Sub AppendGridToWordDoc(ByRef voGrid As MsFlexgrid, Optional ByRef voDoc As Word.Document)
Dim oWord As Word.Application
Dim nRow As Integer
Dim nCol As Integer
Dim sBuffer As String
If Not Nothing Is voGrid Then
For nRow = 0 To voGrid.Rows - 1
For nCol = 0 To voGrid.Cols - 1
sBuffer = sTemp & voGrid.TextMatrix(row, col)
If nCol = voGrid.Cols - 1 Then
sBuffer = sBuffer & vbCrLf
Else
sBuffer = sBuffer & vbTab
End If
Next nCol
Next nRow
If Nothing Is voDoc Then
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Nothing Is oWord Then
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
End If
Set voDoc = oWord.Documents.Add
End If
With voDoc.Bookmarks("\EndOfDoc").Range
.Text = sBuffer
.ConvertToTable vbTab, Format:=wdTableFormatColorful2 '9
End With
End If
End Sub
ici, on peux fournir une grille en parametre, ainsi qu'un document word auquel on souhaite ajouter notre tableau (l'ajout se fait systématiquement à la fin du document)
on utilise également une petite astuce (GetObject) permettant de se raccrocher à une instance Word existante (plus rapide: pas besoin de CreateObject)
13 mai 2009 à 11:38
plus utile sous la forme d'une fonction réutilisable.