Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro :
Déplacer ou copier / Nouveau classeur
Enregistrer ss : / Format .txt
Copier / Coller
Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro :
Sub gSaveTxt()
Sheets(".txt").Select
Sheets(".txt").Copy
ChDir "C:\temp"
ActiveWorkbook.SaveAs Filename:="C:\temp\SOFRCORP.txt",
FileFormat:=xlText _
, CreateBackup:=False
End Sub
Résultat : les données sont collés comme dans Excel mais avec un " en début
et en fin de chaque donnée de cellule Excel
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Daniel
Bonsoir. Avec XL2003, j'ai exécuté ta macro et j'obtiens des éléments séparés par des tabulations. Cordialement. Daniel "oBa" a écrit dans le message de news: %
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début et en fin de chaque donnée de cellule Excel
Et c'est très très génant pour moi...
Des idées ??
Merci d'avance.
Olivier.
Bonsoir.
Avec XL2003, j'ai exécuté ta macro et j'obtiens des éléments séparés par des
tabulations.
Cordialement.
Daniel
"oBa" <zolibail@yahoo.fr> a écrit dans le message de news:
%23wnZmEYkGHA.3848@TK2MSFTNGP04.phx.gbl...
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro :
Déplacer ou copier / Nouveau classeur
Enregistrer ss : / Format .txt
Copier / Coller
Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro :
Sub gSaveTxt()
Sheets(".txt").Select
Sheets(".txt").Copy
ChDir "C:temp"
ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt",
FileFormat:=xlText _
, CreateBackup:úlse
End Sub
Résultat : les données sont collés comme dans Excel mais avec un " en
début et en fin de chaque donnée de cellule Excel
Bonsoir. Avec XL2003, j'ai exécuté ta macro et j'obtiens des éléments séparés par des tabulations. Cordialement. Daniel "oBa" a écrit dans le message de news: %
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début et en fin de chaque donnée de cellule Excel
Et c'est très très génant pour moi...
Des idées ??
Merci d'avance.
Olivier.
docm
Voici une solution proposée par cpearson que l'on appelle par ExportToTextFile Fichier, séparateur , SauverSélection Exemple: ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _ Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String Dim FNum As Integer Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer Dim CellValue As String
Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile
If SelectionOnly = True Then With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" 'Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx
EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum
End Sub
"oBa" wrote in message news:#
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début
et en fin de chaque donnée de cellule Excel
Et c'est très très génant pour moi...
Des idées ??
Merci d'avance.
Olivier.
Voici une solution proposée par cpearson que l'on appelle par
ExportToTextFile Fichier, séparateur , SauverSélection
Exemple:
ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _
Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = "" 'Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum
End Sub
"oBa" <zolibail@yahoo.fr> wrote in message
news:#wnZmEYkGHA.3848@TK2MSFTNGP04.phx.gbl...
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro :
Déplacer ou copier / Nouveau classeur
Enregistrer ss : / Format .txt
Copier / Coller
Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro :
Sub gSaveTxt()
Sheets(".txt").Select
Sheets(".txt").Copy
ChDir "C:temp"
ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt",
FileFormat:=xlText _
, CreateBackup:úlse
End Sub
Résultat : les données sont collés comme dans Excel mais avec un " en
début
Voici une solution proposée par cpearson que l'on appelle par ExportToTextFile Fichier, séparateur , SauverSélection Exemple: ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _ Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String Dim FNum As Integer Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer Dim CellValue As String
Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile
If SelectionOnly = True Then With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" 'Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx
EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum
End Sub
"oBa" wrote in message news:#
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début
et en fin de chaque donnée de cellule Excel
Et c'est très très génant pour moi...
Des idées ??
Merci d'avance.
Olivier.
oBa
Super, ca marche !!!!
Merci beaucoup.
@+
Olivier.
"docm" a écrit dans le message de news: %
Voici une solution proposée par cpearson que l'on appelle par ExportToTextFile Fichier, séparateur , SauverSélection Exemple: ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _ Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String Dim FNum As Integer Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer Dim CellValue As String
Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile
If SelectionOnly = True Then With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" 'Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx
EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum
End Sub
"oBa" wrote in message news:#
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début
et en fin de chaque donnée de cellule Excel
Et c'est très très génant pour moi...
Des idées ??
Merci d'avance.
Olivier.
Super, ca marche !!!!
Merci beaucoup.
@+
Olivier.
"docm" <no_spam@trust.net> a écrit dans le message de news:
%23HKNawakGHA.4276@TK2MSFTNGP03.phx.gbl...
Voici une solution proposée par cpearson que l'on appelle par
ExportToTextFile Fichier, séparateur , SauverSélection
Exemple:
ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _
Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String
Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = "" 'Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum
End Sub
"oBa" <zolibail@yahoo.fr> wrote in message
news:#wnZmEYkGHA.3848@TK2MSFTNGP04.phx.gbl...
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro :
Déplacer ou copier / Nouveau classeur
Enregistrer ss : / Format .txt
Copier / Coller
Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro :
Sub gSaveTxt()
Sheets(".txt").Select
Sheets(".txt").Copy
ChDir "C:temp"
ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt",
FileFormat:=xlText _
, CreateBackup:úlse
End Sub
Résultat : les données sont collés comme dans Excel mais avec un " en
début
Voici une solution proposée par cpearson que l'on appelle par ExportToTextFile Fichier, séparateur , SauverSélection Exemple: ExportToTextFile "c:test.txt", chr(9) , FALSE
Public Sub ExportToTextFile(FName As String, _ Sep As String, SelectionOnly As Boolean)
Dim WholeLine As String Dim FNum As Integer Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer Dim CellValue As String
Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile
If SelectionOnly = True Then With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With Else With ActiveSheet.UsedRange StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With End If
Open FName For Output Access Write As #FNum
For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = "" 'Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLine Next RowNdx
EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum
End Sub
"oBa" wrote in message news:#
Bonsoir à tous,
Sur Excel 97, je souhaite engistrer un onglet Excel dans un fichier .txt.
Voilà la manip. ss macro : Déplacer ou copier / Nouveau classeur Enregistrer ss : / Format .txt Copier / Coller Résultat : mes données sont collés dans le .txt à l'identique d'Excel.
Voilà la macro : Sub gSaveTxt() Sheets(".txt").Select Sheets(".txt").Copy ChDir "C:temp" ActiveWorkbook.SaveAs Filename:="C:tempSOFRCORP.txt", FileFormat:=xlText _ , CreateBackup:úlse End Sub Résultat : les données sont collés comme dans Excel mais avec un " en début