j'ai un petit problème lors de l'enregistrement d'une macro !
je vous explique, je dois enregistrer une macro pour délimiter un long fichier texte mais j'y arrive pas !
pouvez vous m'aider
' Create a new workbook with one worksheet in it.
Workbooks.Add template:=xlWorksheet
Counter = 1
' Loop until the end of file is reached.
Do While Seek(FileNum) <= LOF(FileNum)
' Display importing row number on status bar.
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
' Store one line of text from file to variable.
Line Input #FileNum, ResultStr
' Store variable data into active cell.
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If
If ActiveCell.Row = 65536 Then
' If on the last row then add a new sheet.
ActiveWorkbook.Sheets.Add
Else
' If not the last row then go one cell down.
ActiveCell.Offset(1, 0).Select
End If
' Increment the counter by 1.
Counter = Counter + 1
' Start again at top of 'do while' statement.
Loop
' Close the open text file.
Close
' Remove message from status bar.
Application.StatusBar = False
End Sub
merci bcp mais il me dit Erreur d'exécution 1004
Erreur définie par l'application ou par l'objet
Sub ab()
Dim oFSO
Dim oFS
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFS = oFSO.OpenTextFile("c:\temp\test.txt")
Do Until oFS.AtEndOfStream
i = i + 1
Cells(i, 1) = oFS.ReadLine
Loop
End Sub
PS:Bonjour Hasco
C'est moi que tu assimiles à Skoobi?
Si c'est le cas, merci de l'honneur
Hamza, si nous te demandons un bout de ton fichier texte c'est pour en connaître la structure exacte et voir ce que l'on peut faire pour toi.
Chaque cas est un cas particulier avec des besoins particulier.
A+
[Edit] Hey L'agrafe, je m'ai encore trompé
JC soleil radieux, sous le châtaigner, je me rafraichis d'une légère brise marine. (fin bulletin méto chalandaise)
' Create a new workbook with one worksheet in it.
Workbooks.Add template:=xlWorksheet
Counter = 1
' Loop until the end of file is reached.
Do While Seek(FileNum) <= LOF(FileNum)
' Display importing row number on status bar.
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
' Store one line of text from file to variable.
Line Input #FileNum, ResultStr
' Store variable data into active cell.
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If
If ActiveCell.Row = 65536 Then
' If on the last row then add a new sheet.
ActiveWorkbook.Sheets.Add
Else
' If not the last row then go one cell down.
ActiveCell.Offset(1, 0).Select
End If
' Increment the counter by 1.
Counter = Counter + 1
' Start again at top of 'do while' statement.
Loop
' Close the open text file.
Close
' Remove message from status bar.
Application.StatusBar = False
End Sub
L'erreur est au niveau de FileName = Application.GetOpenFilename("TEXT")
Sinon, la macro indiquée par Hascoobi doit fonctionner
PS: tu trouveras aussi des exemples de fils de discussions relatif à l'import de fichiers de plus de 65000 lignes.
Il faut juste le temps de retrouver les fils en question avec le moteur de recherche du forum
pour ce code ca a laide très interessant si il decoupe mon fichier sur plusieurs feuilles comme ca je choisité les feuilles dont joré besoin mais apparement il ne marche pas !
il me laisse choisir le fichier .log ke je veux
il louvres sur un nouveau classeur mais juste une seule feuille et elle n'est même pas complète il manque bcp de données !!
Sub LargeFileImport()
' Dimension Variables.
Dim ResultStr As String
Dim FileName As Variant
Dim FileNum As Integer
Dim Counter As Double
' Ask User for file's name.
FileName = Application.GetOpenFilename("Fichier Texte,*.log")
' Check for no entry.
If FileName = False Then End
' Get next available file handle number.
FileNum = FreeFile()
' Open text file for input.
Open FileName For Input As #FileNum
' Create a new workbook with one worksheet in it.
Workbooks.Add template:=xlWorksheet
Counter = 1
' Loop until the end of file is reached.
Do While Seek(FileNum) <= LOF(FileNum)
' Display importing row number on status bar.
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
' Store one line of text from file to variable.
Line Input #FileNum, ResultStr
' Store variable data into active cell.
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If
If ActiveCell.Row = 65536 Then
' If on the last row then add a new sheet.
ActiveWorkbook.Sheets.Add
Else
' If not the last row then go one cell down.
ActiveCell.Offset(1, 0).Select
End If
' Increment the counter by 1.
Counter = Counter + 1
' Start again at top of 'do while' statement.
Loop
' Close the open text file.
Close
' Remove message from status bar.
Application.StatusBar = False