Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" a écrit dans le message de news:
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" a écrit dans le message de news:
%Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" <fromto@online.fr> a écrit dans le message de news:
u94FJhdFFHA.3596@TK2MSFTNGP12.phx.gbl...
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" <michdenis@hotmail.com> a écrit dans le message de news:
%23g453tbFFHA.2296@TK2MSFTNGP15.phx.gbl...
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" a écrit dans le message de news:
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" a écrit dans le message de news:
%Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" a écrit dans le message de news:
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" a écrit dans le message de news:
%Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" <fromto@online.fr> a écrit dans le message de news:
u94FJhdFFHA.3596@TK2MSFTNGP12.phx.gbl...
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" <michdenis@hotmail.com> a écrit dans le message de news:
%23g453tbFFHA.2296@TK2MSFTNGP15.phx.gbl...
Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!
Bonjour Fromto,
voici une procédure et commentaire émanant d'un MVP du forum anglophone
sur Excel : M. Pearson
Tu me permettras de ne pas te traduire les explications qu'il donne ....en
français !
Pour ton bénéfice, tu insères ces 2 procédures dans un module standard, et
tu appelles celle-ci :
Public Sub DoTheImport
'Excel does not give you a method to import
'a text file directly into an existing worksheet.
'The Text Import Wizard will always create a new
'workbook. The macro that follows allows you to
'import a delimited text file directly into the
'active worksheet, beginning in the active cell.
'The macro ImportTextFile will import the file
'specified by FName into the active worksheet.
'Imported values begin in the active cell, and each
'line of the text file are placed on the same row
'of the worksheet. Each subsequent line of the text
'file is place on the next row of the worksheet.
'Imported values, separated by the character specified
'by Sep, are placed in separate columns. Each line
'in the text file does not need to contain the same
'number of values. If there is a blank line in the text
'file, a blank row will appear in the worksheet.
'-----------------------------------------------
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
'On Error GoTo EndMacro:
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
'-----------------------------------------------
'You can call this macro from another VBA
'procedure as follows:
'ImportTextFile "c:temptest.txt", ";"
'Since this code has parameters, it will not appear
'in the standard "Macros" dialog list (ALT+F8).
'The following procedure will prompt you for the
'filename and delimiter character, and then run the
'ImportTextFile procedure.
Public Sub DoTheImport()
Dim FName As Variant
Dim Sep As String
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt,All Files (*.*),*.*")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
Sep = InputBox("Enter a single delimiter character.", _
"Import Text File")
ImportTextFile CStr(FName), Sep
End Sub
'-----------------------------------------------
Salutations!
"fromto" a écrit dans le message de news:
Merci,
Mais ce n'est pas tout à fait cela que je cherche, je voudrais ouvrir le
fichier et nommer nouvelle feuille dans le même classeur.
"MichDenis" a écrit dans le message de news:
%Bonjour Fromto,
Directement de l'aide d'excel :
dim filetoOpen as variant
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
End If
Salutations!