MsFlexGrid ----> Excel

Résolu
cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 - Modifié le 10 janv. 2005 à 09:18
cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 - 10 janv. 2005 à 09:18
Salut, tous le monde,
J'utilise cette fonction pour extraire les données d'un MsFlexGrid vers Excel...
ça Fonctionne bien sauf pour les dates...

en les ecrivant dans excel il m'inverse parfois les jour et les mois.......
Comment ca se fait ? Avez vous une fonction à me proposer ? ou des Corrections ?
Merci d'avance
Public Sub FlexGrid_To_Excel(TheFlexgrid As MSFlexGrid,TheRows As Integer, TheCols As Integer, Optional GridStyle As Integer = 1, Optional WorkSheetName  As String)
    
Dim objXL As New Excel.Application
Dim wbXL As New Excel.Workbook
Dim wsXL As New Excel.Worksheet
Dim intRow As Integer ' counter
Dim intCol As Integer ' counter


If Not IsObject(objXL) Then
    MsgBox "Vous Avez Besoin d' Excel",vbExclamation, "Envoie dans Excel"
    Exit Sub
End If


On Error Resume Next


ObjXL.Visible = True
Set wbXL = objXL.Workbooks.Add
Set wsXL = objXL.ActiveSheet



With wsXL
    If Not WorkSheetName = "" Then
        .Name = WorkSheetName
    End If
End With
    
For intRow = 1 To TheRows
    For intCol = 1 To TheCols
        With TheFlexgrid
            wsXL.Cells(intRow, intCol).Value = _
               .TextMatrix(intRow - 1, intCol - 1) & " "
        End With
    Next
Next


End Sub

It@li@

2 réponses

cs_ITALIA Messages postés 2169 Date d'inscription vendredi 20 avril 2001 Statut Membre Dernière intervention 30 juin 2009 9
10 janv. 2005 à 09:18
Merci Programmix mais le .Formula ne change rien, j'ai trouvé une solution, en remplaçant :

wsXL.Cells(intRow, intCol).Value = .TextMatrix(intRow - 1, intCol - 1) & " "

Par

If Len(.TextMatrix(intRow - 1, intCol - 1)) = 10 And IsDate(.TextMatrix(intRow - 1, intCol - 1)) Then
wsXL.Cells(intRow, intCol).Value = Format(.TextMatrix(intRow - 1, intCol - 1) & " ", "mm/dd/yy")
Else
wsXL.Cells(intRow, intCol).Value = .TextMatrix(intRow - 1, intCol - 1) & " "
End If

It@li@
1
cs_PROGRAMMIX Messages postés 1133 Date d'inscription mercredi 2 octobre 2002 Statut Membre Dernière intervention 24 juillet 2011 2
8 janv. 2005 à 19:50
Le pourquoi, je ne le sais pas exactement... une histoire de "paramétrage de langue" au niveau des applications.

Aussi, souvent au lieu de taper Cells(intRow, intCol).Value, j'utilise plutôt Cells(intRow, intCol).Formula.

A toi de voir si ça change quelque chose pour toi.

Programmix
0
Rejoignez-nous