[RESOLU] Ouvrir boite de dialogue et obtenir emplacement du fichier dans une cellule

  • Initiateur de la discussion Initiateur de la discussion kayl83
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

K

kayl83

Guest
Bonjour,

j'essaye d'obtenir dans une cellule le chemin d'accès de mon fichier.

J'ai trouvé une macro qui m'affiche le chemin dans un messagebox:
Code:
Sub Main()

    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem
                Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing

End Sub

Mais je voudrais que le chemin s'inscrive aussi dans une cellule (exemple: D2).

J'ai essayé çà mais sans succès:
Code:
UCase(Range("D2")) = vrtSelectedItem
 
Dernière modification par un modérateur:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD
Assurez vous de marquer un message comme solution pour une meilleure transparence.

Discussions similaires

J
Réponses
0
Affichages
615
jptaz15
J
B
Réponses
1
Affichages
887
Bullrot
B
G
Réponses
0
Affichages
1 K
guiboubou233
G
H
Réponses
5
Affichages
2 K
hokousai
H
K
Réponses
8
Affichages
2 K
kamal.elkakiri
K
P
Réponses
0
Affichages
841
pierrealti
P
M
Réponses
13
Affichages
5 K
M
N
Réponses
1
Affichages
650
New_VBA_User
N
B
Réponses
0
Affichages
899
Bruno67
B
Retour