VBA Excel copie de texte fichier de feuille de calcul

Je suis en train de tirer des statistiques d'une colonne spécifique dans un fichier texte et j'ai pensé que la meilleure façon de le faire pourrait être de copier tout le contenu du fichier texte dans une feuille de calcul excel et de compter à partir de là (sinon je serais besoin d'essayer de lire seulement une ligne directement à partir du fichier excel). Voici le code de ce que j'ai à ce jour:

Dim filePath As String
Dim currentValue As String
Dim iRow As Long
Dim iCol As Long
Dim badAddress As Long
Dim coverageNoListing As Long
Dim activeListing As Long
Dim noCoverageNoListing As Long
Dim inactiveListing As Long
Dim fso As Object
Dim f As Object

'' filePath would include entire file name (picked from a browser button)
filePath = ActiveSheet.Range("B2").Text

'' Makes sure there isn't a sheet named "Temp_Text_File"
For Each testSheet In ActiveWorkbook.Worksheets
    If testSheet.Name Like "Temp_Text_File" Then flag = True: Exit For
Next

'' If there is a sheet named "Temp_Text_File" it will be deleted
If flag = True Then
    Application.DisplayAlerts = False
    ActiveWorkbook.Sheets("Temp_Text_File").Delete
    Application.DisplayAlerts = True
End If

'' Recreate sheet
Sheets.Add.Name = "Temp_Text_File"
'' Here I would want to copy everything (similar to manually doing "Ctrl+A" then "Ctrl+C") from the text file

'' Then paste into worksheet (similar to manually doing "Ctrl+V") within this created worksheet range("A1")

'' Delete at the end (user has no need for it)
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("Temp_Text_File").Delete
Application.DisplayAlerts = True

Merci,

Jesse Smothermon

OriginalL'auteur Jesse Smothermon | 2011-04-29