Pour le point n°2, j'utilise un module qui me fourni des interfaces simplement !
Ca utilise les API de windows, ca marche sous win95, win98, win2000 et win XP sûr, j'ai pas testé sous les autres Windows.
Met ceci dans un module :
Option Explicit
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function OuvreChoixFichier() As String
Dim sRet As String
Dim of As OPENFILENAME
sRet = String(254, 0&)
of.flags = 4
of.hInstance = App.hInstance
of.lpstrInitialDir = "c:\"
of.lpstrTitle = "Charger un fichier"
of.hwndOwner = 0&
of.nFileExtension = 1
of.lpstrFile = sRet
of.nMaxFile = 254
of.lStructSize = Len(of)
of.lpstrFilter = "Fichier texte(*.text)" & vbNullChar & _
"*.txt" & vbNullChar & _
"Tous les fichiers (*.*)" & vbNullChar & _
"*.*" & vbNullChar & vbNullChar
If GetOpenFileName(of) > 0 Then
OuvreChoixFichier = Left(of.lpstrFile, InStr(1, of.lpstrFile, Chr(0)) - 1)
End If
End Function
Public Function OuvreSauveFichier(sExt As String, Optional sChemin As String = vbNullString) As String
Dim sRet As String
Dim of As OPENFILENAME
sRet = String(254, 0&)
of.flags = 1
of.hInstance = App.hInstance
of.lpstrInitialDir = sChemin
of.lpstrTitle = "Enregistrer sous ..."
of.hwndOwner = 0&
of.nFileExtension = 1
of.lpstrFile = sRet
of.nMaxFile = 254
If sExt = "txt" Then
of.lpstrDefExt = "txt"
of.lpstrFilter = "fichier Texte (*.txt)" & vbNullChar & _
"*.txt" & vbNullChar & _
"Tous les fichiers (*.*)" & vbNullChar & _
"*.*" & vbNullChar & vbNullChar
Else
of.lpstrFilter = "Tous les fichiers (*.*)" & vbNullChar & _
"*.*" & vbNullChar & vbNullChar
End If
of.lStructSize = Len(of)
If GetSaveFileName(of) > 0 Then
OuvreSauveFichier = Left(of.lpstrFile, InStr(1, of.lpstrFile, Chr(0)) - 1)
End If
End Function
Public Function getRepertoire(Optional repertoireInit As String = "c:\") As String
Dim oShell As Object
Dim oFolder As Object
Dim oFolderItem As Object
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&, repertoireInit)
If Not oFolder Is Nothing Then
Set oFolderItem = oFolder.Self
getRepertoire = oFolderItem.Path
End If
End Function
et ensuite, depuis n'importe où tu peux faire :
s = OuvreChoixFichier()
MsgBox (s)
et 's' contiendra le fichier choisi, ou sera vide si la personne a annuler
s = OuvreSauveFichier("txt")
MsgBox (s)
et 's' contiendra le fichier choisi pour l'enregistrement, ou sera vide si la personne a annuler
s = getRepertoire()
MsgBox (s)
et 's' contiendra le répertoire sélectionné ou sera vide si la personne a annuler