bonsoir les experts du VBA,
voici ma problèmatique : Je suis sur mon premier programme en VBA, et j'en **** des ronds de chapeau. Pour vous la faire courte mon programme doit comporter (me semble t'il) 4 actions , 1) sur mon fichier xlsm je vais créer un nouvelle onglet 2) j'importe les données dans ce nouvelle onglet ----c'est là que ça pêche 3) je recupére ces données pour les mettre dans le bon onglet a la suite de celle existante, ensuite je vais voir comment mettre à jour mes tableaux croisé (4) , mais cela ne semble pas trés compliqué.
Monproblème viens du fait qu'il faut que j'ouvre une boite dialogue pour choisir le fichier à importer, et celui-ci change de nom tous le temps, je met mon code entier pour être plus claire.
Soyez indulgent c'est mon premier, merci beaucoup pour votre aide. (c'est ça ou je me fou par la fenêtre
Wucleus
_______________________________________________________________
Sub Open_Directo()
'1 ) bon là création de ma sheet pour l'import
Sheets.Add.Name = ("tmp")
'1 ) je me met sur la bonne cellule
ActiveSheet.Range("A1").Select
'2 )ouverture d'une boite de dialogue
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "C:\Documents and Settings\*****\"
.Show
If .SelectedItems.Count > 0 Then Workbooks.Open .SelectedItems(1)
End With
'2) importer mon csv du répertoire qui va bien
Sheets("tmp").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Documents and Settings\*****\", Destination:=Range("$A$2"))
.Name = "Wiibe_Export06-05-2011"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
' 3 )selection de ma plage à copier sans les entêtes
Sheets("tmp").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Données").Select
Range("A4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
voici ma problèmatique : Je suis sur mon premier programme en VBA, et j'en **** des ronds de chapeau. Pour vous la faire courte mon programme doit comporter (me semble t'il) 4 actions , 1) sur mon fichier xlsm je vais créer un nouvelle onglet 2) j'importe les données dans ce nouvelle onglet ----c'est là que ça pêche 3) je recupére ces données pour les mettre dans le bon onglet a la suite de celle existante, ensuite je vais voir comment mettre à jour mes tableaux croisé (4) , mais cela ne semble pas trés compliqué.
Monproblème viens du fait qu'il faut que j'ouvre une boite dialogue pour choisir le fichier à importer, et celui-ci change de nom tous le temps, je met mon code entier pour être plus claire.
Soyez indulgent c'est mon premier, merci beaucoup pour votre aide. (c'est ça ou je me fou par la fenêtre
Wucleus
_______________________________________________________________
Sub Open_Directo()
'1 ) bon là création de ma sheet pour l'import
Sheets.Add.Name = ("tmp")
'1 ) je me met sur la bonne cellule
ActiveSheet.Range("A1").Select
'2 )ouverture d'une boite de dialogue
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "C:\Documents and Settings\*****\"
.Show
If .SelectedItems.Count > 0 Then Workbooks.Open .SelectedItems(1)
End With
'2) importer mon csv du répertoire qui va bien
Sheets("tmp").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Documents and Settings\*****\", Destination:=Range("$A$2"))
.Name = "Wiibe_Export06-05-2011"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
' 3 )selection de ma plage à copier sans les entêtes
Sheets("tmp").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Données").Select
Range("A4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub