Créer une fenêtre browse pour stocker un fichier

Sarah0606

XLDnaute Nouveau
Re,

je dois créer un fichier .txt mais avant de le créer je dois spécifier un chemin alors au lieu de le rentrer à la main je trouvais plus classe d'ouvrir une fenêtre browse comme lorsqu'on enregistre un fichier word par exemple.

Qqn sait-il faire ça?
 

Sarah0606

XLDnaute Nouveau
Re : Créer une fenêtre browse pour stocker un fichier

Je me réponds à moi même mais ça peut servir à d'autres...

Alors voilà j'ai trouvé ça:

Sub DialogueFichiers()
Dim fd As FileDialog
'Crée une boite de dialogue de sélection de fichiers :
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Show
If fd.SelectedItems.Count > 0 Then
MsgBox fd.SelectedItems(1)
End If
Set fd = Nothing
End Sub

Mais je vois pas comment le connecter à un bouton, ça va venir...
 

mromain

XLDnaute Barbatruc
Re : Créer une fenêtre browse pour stocker un fichier

bonjour

je t'ai juste remplacé le Sub en une Function

Code:
Option Explicit


Public Function DialogueFichiers() As String
DialogueFichiers = ""
Dim fd As FileDialog
'Crée une boite de dialogue de sélection de fichiers :
Set fd = Application.FileDialog(msoFileDialogFilePicker)


dialog_show:
fd.Show
'limite la sélection à un fichier
If fd.SelectedItems.Count > 1 Then GoTo dialog_show


DialogueFichiers = fd.SelectedItems(1)
Set fd = Nothing
End Function


Sub recup_file()
Dim toto As String
toto = DialogueFichiers
MsgBox toto
End Sub

et j'ai limité la sélection à un fichier

maintenant il te reste plus qu'à utiliser la fonction dans ton bouton

a+
 

tototiti2008

XLDnaute Barbatruc
Re : Créer une fenêtre browse pour stocker un fichier

Bonjour à tous,

pour info :

Code:
fd.AllowMultiSelect = False 'Permet de limiter la sélection à un élément
fd.InitialFileName = "C:\Test" 'Permet de spécifier le premier endroit affiché

d'autres options sont disponibles...
 

Sarah0606

XLDnaute Nouveau
Re : Créer une fenêtre browse pour stocker un fichier

Alors voilà ce qe j'ai fait et ça merde total!!

Code:
Private Sub CommandButton2_Click()

Option Explicit


Public Function DialogueFichiers() As String
DialogueFichiers = ""
Dim fd As FileDialog
'Crée une boite de dialogue de sélection de fichiers :
Set fd = Application.FileDialog(msoFileDialogSaveAs)


dialog_show:
fd.Show
'limite la sélection à un fichier
If fd.SelectedItems.Count > 1 Then GoTo dialog_show


DialogueFichiers = fd.SelectedItems(1)
Set fd = Nothing
End Function



End Sub

Sub recup_file()
Dim toto As String
toto = DialogueFichiers
MsgBox toto
End Sub

J'ai besoin de dragibus je pète un plomb
 

tototiti2008

XLDnaute Barbatruc
Re : Créer une fenêtre browse pour stocker un fichier

Code:
[COLOR=red]Private Sub CommandButton2_Click()
[/COLOR]
Option Explicit


Public Function DialogueFichiers() As String
DialogueFichiers = ""
Dim fd As FileDialog
'Crée une boite de dialogue de sélection de fichiers :
Set fd = Application.FileDialog(msoFileDialogSaveAs)


dialog_show:
fd.Show
'limite la sélection à un fichier
If fd.SelectedItems.Count > 1 Then GoTo dialog_show


DialogueFichiers = fd.SelectedItems(1)
Set fd = Nothing
End Function



[COLOR=red]End Sub[/COLOR]

Sub recup_file()
Dim toto As String
toto = DialogueFichiers
MsgBox toto
End Sub

Vires ce qui est en rouge, je ne sais pas ce que ça fait là ?
 

tototiti2008

XLDnaute Barbatruc
Re : Créer une fenêtre browse pour stocker un fichier

alors fait ça :

Code:
Option Explicit


Public Function DialogueFichiers() As String
DialogueFichiers = ""
Dim fd As FileDialog
'Crée une boite de dialogue de sélection de fichiers :
Set fd = Application.FileDialog(msoFileDialogSaveAs)


dialog_show:
fd.Show
'limite la sélection à un fichier
If fd.SelectedItems.Count > 1 Then GoTo dialog_show


DialogueFichiers = fd.SelectedItems(1)
Set fd = Nothing
End Function



[COLOR=#ff0000]Private Sub CommandButton2_Click()[/COLOR]
Dim toto As String
toto = DialogueFichiers
MsgBox toto
End Sub
 

Discussions similaires

Réponses
3
Affichages
572
Compte Supprimé 979
C

Statistiques des forums

Discussions
312 490
Messages
2 088 875
Membres
103 980
dernier inscrit
grandmasterflash38