Récupérer l'adresse d'un fichier : OK. Mais comment l'utiliser ?

Jpeg69 Messages postés 28 Date d'inscription vendredi 9 mars 2007 Statut Membre Dernière intervention 8 février 2008 - 1 mai 2007 à 11:49
Jpeg69 Messages postés 28 Date d'inscription vendredi 9 mars 2007 Statut Membre Dernière intervention 8 février 2008 - 1 mai 2007 à 16:48
Bonjour,


Je cherche à enregistrer dans un fichier excel des données d'un autre
fichier excel. La difficulté est que ces fichier change de répertoir et
donc d'adresse.


Ainsi j'ai imaginé une solution en demandant, pour actualiser les liens, l'emplacement du fichier par une boite de dialogue :

Sub Macro1()
 
'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 AsVariant
 
'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 = -1Then
 
'Step through each string in the FileDialogSelectedItems collection.
ForEach 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
EndIf
EndWith
 
'Set the object variable to Nothing.
Set fd = Nothing

EndSub


Code trouvé sur l'aide d'excel.


Maintenant mon problème est que je n'arrive pas à utiliser l'adresse trouvé pour actualiser les liens.


Merci de vos réponses.

3 réponses

Jpeg69 Messages postés 28 Date d'inscription vendredi 9 mars 2007 Statut Membre Dernière intervention 8 février 2008
1 mai 2007 à 14:38
Afin d'éclaicir mon problème :

Exemple : A1 ='C:\Users\Jpeg\[NomDuFichier.xls]Feuille1'!$A$2

Si le fichier change de place le lien ne marche plus.

Je récupère donc l'emplacement du fichier mais je n'arrive pas à l'utiliser.

Voila...
0
mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
1 mai 2007 à 15:27
Salut,

ben avec la réponse de ton mesgbox, tu as le Path, il reste à imbriquer cette chaine de caractères avec le nom du fichier..

Dim FileFullName As String
ForEach vrtSelectedItem In .SelectedItems
   FileFullName = vrtSelectedItem & "\Ton fichier.xls"
Next vrtSelectedItem

WorkBooks.Open FileFullName

@++

<hr width="100%" size="2" />
  --Mortalino--
Le mystérieux chevalier, ~Provençal, le Gaulois~
  
0
Jpeg69 Messages postés 28 Date d'inscription vendredi 9 mars 2007 Statut Membre Dernière intervention 8 février 2008
1 mai 2007 à 16:48
Merci à toi Mortalino,

... mais tu ne répond pas vraiment à mon problème puisque le nom du fichier se trouve déjà dans la variable vrtSelectedItem.

Cependant ta concaténation pourrait bien m'aiguiller.

@++
0
Rejoignez-nous