Choix d'un fichier
Résolu
ghislaineg
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
ghislaineg -
ghislaineg -
Bonjour,
j'ai une macro qui va chercher un fichier .csv mais j'aimerais que l'utilisateur choisisse sont fichier et par la suite l'importe..
voici ma macro de base:
Sub fiche()
'
' fiche Macro
'
' Touche de raccourci du clavier: Ctrl+y
Range("a1:e800").Select
Selection.ClearContents
rep = InputBox("nom du fichier")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrateur\Bureau\" & rep & ".csv", _
Destination:=Range("$A$1"))
.Name = "& rep"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:E").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Range("A1:D2").Select
'ActiveWorkbook.Names.Add Name:="ente", RefersToR1C1:="=Feuil1!R1C1:R2C4"
'ActiveWorkbook.Names("ente").Comment = ""
With ActiveSheet.PageSetup
'en-tête de page
.LeftHeader = Sheets(1).Range("a1") '<-- contenu de la cellule A1 (sans précision = style par défaut)
.CenterHeader = "&G&12&""Comic Sans Ms""Sommaire de Pesée" '<-- texte (style gras + taille 12 + style police)
.RightHeader = Sheets(1).Range("d1") '<-- texte + indice
'pied de page
.LeftFooter = "&I&D / &T" '<-- date / heure (style italique)
.CenterFooter = "&G&A" & Chr(10) & "&G&F" '<-- nom feuille (activation style gras) + saut de ligne + nom fichier (désactivation style gras)
.RightFooter = "&8&P/&N" '<-- numéro de page / nombre de pages (taille 8)
End With
End Sub
Je sais que c'est cette section qur je dois changer :rep = InputBox("nom du fichier")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrateur\Bureau\" & rep & ".csv", _
Destination:=Range("$A$1"))
.Name = "& rep"
pouvez-vous m'aider..
Salutation Ghislaine
End Sub
j'ai une macro qui va chercher un fichier .csv mais j'aimerais que l'utilisateur choisisse sont fichier et par la suite l'importe..
voici ma macro de base:
Sub fiche()
'
' fiche Macro
'
' Touche de raccourci du clavier: Ctrl+y
Range("a1:e800").Select
Selection.ClearContents
rep = InputBox("nom du fichier")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrateur\Bureau\" & rep & ".csv", _
Destination:=Range("$A$1"))
.Name = "& rep"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:E").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Range("A1:D2").Select
'ActiveWorkbook.Names.Add Name:="ente", RefersToR1C1:="=Feuil1!R1C1:R2C4"
'ActiveWorkbook.Names("ente").Comment = ""
With ActiveSheet.PageSetup
'en-tête de page
.LeftHeader = Sheets(1).Range("a1") '<-- contenu de la cellule A1 (sans précision = style par défaut)
.CenterHeader = "&G&12&""Comic Sans Ms""Sommaire de Pesée" '<-- texte (style gras + taille 12 + style police)
.RightHeader = Sheets(1).Range("d1") '<-- texte + indice
'pied de page
.LeftFooter = "&I&D / &T" '<-- date / heure (style italique)
.CenterFooter = "&G&A" & Chr(10) & "&G&F" '<-- nom feuille (activation style gras) + saut de ligne + nom fichier (désactivation style gras)
.RightFooter = "&8&P/&N" '<-- numéro de page / nombre de pages (taille 8)
End With
End Sub
Je sais que c'est cette section qur je dois changer :rep = InputBox("nom du fichier")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrateur\Bureau\" & rep & ".csv", _
Destination:=Range("$A$1"))
.Name = "& rep"
pouvez-vous m'aider..
Salutation Ghislaine
End Sub
A voir également:
- Choix d'un fichier
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Fichier rar - Guide
- Fichier .dat - Guide
merci de ton aide cela fonctionne tres bien .:)
Salutation Ghislaine