Tu places dans ton projet 1 "class module" avec cette fonction:
Public Function ExportGridToFile(Mygrid1 As MSFlexGrid, ByVal strFileName As String, _
Optional ByVal strSep As String = vbTab) As Boolean
Dim intFreeFile As Integer 'Numéro du fichier
Dim intCol As Integer, intRow As Integer 'Indices de ligne et colonne de W
Dim Ligne As String 'La ligne à écrire dans le fichier
Dim auxLigne As String * 31
On Error GoTo ExportGridToFile_ERR
'Prend le prochain numéro de fichier
intFreeFile = FreeFile
'Ouvre le fichier en bloquant son accès aux autres applications
Open strFileName For Output Access Write Lock Read Write As #intFreeFile
Ligne = ""
For j = 0 To 1
auxLigne = Mygrid1.TextMatrix(0, j)
Ligne = Ligne & strSep & auxLigne & strSep
Next j
Print #intFreeFile, Ligne
Print #intFreeFile, ""
With Mygrid1
'Pour chaque ligne
For intRow = .FixedRows To .Rows - 1
Ligne = ""
'Pour chaque colonne
For intCol = .FixedCols To .Cols - 1
'Ajoute la valeur de la cellule
'Ligne = Ligne & strSep & .TextMatrix(intRow, intCol) & strSep
auxLigne = .TextMatrix(intRow, intCol)
Ligne = Ligne & strSep & auxLigne & strSep
Next intCol
'Enlève le séparateur final
If strSep <> "" Then Ligne = Left(Ligne, Len(Ligne) - 1)
Print #intFreeFile, Ligne
Next intRow
End With
'Valide le bon fonctionnement de la fonction
ExportGridToFile = True
ExportGridToFile_FIN:
Close #intFreeFile + 1
Exit Function
ExportGridToFile_ERR:
ExportGridToFile = False
Resume ExportGridToFile_FIN
End Function
Dans le form ou se trouve ton msflexgrid, tu ajoute un "commondialog"
Dans le menu editor:
caption=Enregistrer sous
name=save
Tu ecrits ce code:
Private Sub Save_Click()
Form_.Show
Dim sfile As String
With CommonDialog1
.DialogTitle = "Save Data"
.FileName = ""
.CancelError = True
On Error GoTo ErrHandler
'ToDo: set the flags and attributes of the common dialog control
.Flags = &H4
.Filter = "Fichier texte (*.txt)|*.txt"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sfile = .FileName
End With
'verifie si le fichier existe
Dim s As String
Dim resp As Integer
s = Dir(sfile)
If Len(s) <> 0 Then
resp = MsgBox("Fichier '" & sfile & "' existe deja." & Chr(13) & _
"Desires-tu le substituer ?", _
vbYesNo + vbExclamation + vbDefaultButton2, _
" Alerte")
If resp = vbNo Then
Exit Sub
End If
End If
Call ExportGridToFile(MSFlexGrid1, CommonDialog1.FileName)
ErrHandler:
End Sub