erreur 1004

oliv67

XLDnaute Occasionnel
bonjour à tous.


lorsque je transfert du texte en fin de compte je passe par uneonction openfile afin de choisir mon fichier à importer.

en test sur windows xp pas de pb

sur test sur machine avec windows 95 et excel 95
pb j'ai un erreur 1004 au niveau de la variable du fichier pour l'importation

Private Sub CommandButton1_Click()

' Cells.Select
' Selection.ClearContents

With ActiveSheet.QueryTables.Add(Connection:= _
'TEXT;' & ouvertureFichier, Destination:=Range('A5'))
.Name = 'Tedic440_1'
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 932
.TextFileStartRow = 11
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(1, 7, 1, 3, 1, 7, 6, 32, 1, 9, 1, 25)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns('A:A').Select
Selection.Delete shift:=xlToLeft
Range('A1').Select




si qqn à une idée

je vous remercie

olivier [file name=Classeur1_20051123095409.zip size=23906]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/Classeur1_20051123095409.zip[/file]

Message édité par: oliv67, à: 23/11/2005 09:55
 

Pièces jointes

  • Classeur1_20051123095409.zip
    23.3 KB · Affichages: 14

anuky

XLDnaute Occasionnel
Bonjour oliv67,

voici un bout de code que j'utilise pour impoter des fichiers texte :

Code:
Private Sub Macro1()
'
    Dim FileToOpen As Variant
    Dim tmp As Variant

    tmp = ActiveWorkbook.Name
    

    'affiche la boîte de dialogue 'Ouvrir' en ne montrant que les fichiers texte et garde le chemin du fichier en mémoir sans l'ouvrir
    FileToOpen = Application.GetOpenFilename('Fichiers texte (*.txt), *.txt', , , , False)
    If FileToOpen <> False Then
    
    'Importe le fichier texte dont l'adresse a été récupéré précédament dans une nouvelle feuille excel avec la virgule comme séparateur
    Workbooks.OpenText Filename:=FileToOpen, comma:=True
    
    'Copie les données et ferme le classeur créé sans l'enregistrer
    Application.DisplayAlerts = False
    Cells.Select
    Selection.Copy
    ActiveWorkbook.Close
    
    'Sélectionne 'feuil1' du classeur de la macro et y copie les données
    Workbooks(tmp).Activate
    Sheets('feuil1').Activate
    Cells.Select
    Selection.ClearContents
    Range('A1').Select
    ActiveSheet.Paste
    
    Else
    
    Sheets('feuil1').Activate
    
    End If
     
End Sub


Si tu as besioin d'aide n'hésite pas

A+
 
O

oliv67

Guest
ok mais ma selection a été faite pas avec comme séparteur la virgule mais avec l'aide d'importation excel, comme suit :

With ActiveSheet.QueryTables.Add(Connection:= _
'TEXT;' & ouvertureFichier, Destination:=Range('A5'))
.Name = 'Tedic440_1'
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 932
.TextFileStartRow = 11
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(1, 7, 1, 3, 1, 7, 6, 32, 1, 9, 1, 25)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns('A:A').Select
Selection.Delete shift:=xlToLeft
Range('A1').Select

j'ai bessoin d'aide

merci
 

Discussions similaires

Statistiques des forums

Discussions
312 493
Messages
2 088 950
Membres
103 989
dernier inscrit
jralonso