Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Copier de données .txt => .txt

2 réponses
Avatar
Thierry
Bonjour,

Est-il possible, à partir d'Access (VBA), de copier les données d'un
fichier .txt à la suite des données d'un autre fichier .txt ?

(comme la commande Dos : more fichier1.txt >> fichier2.txt )

Merci et bonne soirée.
Thierry

2 réponses

Avatar
Raymond [mvp]
Bonsoir.

tu peux passer par la méthode open, readall / readline, write / writeline,
close qui ne sont pas du tout des commandes Access mais que access accepte
encore d'exécuter.
tu peux passer par un objet Scripting Runtime dont tu trouveras la
documentation sur :
http://officesystem.access.free.fr/scr_scripting_runtime.htm
tu peux passer aussi par une commande Shell pour lancer tout fichier
exécutable

--
@+
Raymond Access MVP http://OfficeSystem.Access.free.fr/
Pour débuter sur le forum: http://www.mpfa.info/

Le multimédia vu par Windows Vista, Office 2007 et Windows Live !!!
http://www.comscamp.com/Tracker/Redirect.ashx?linkid°64304e-439a-45c7-9d2f-c3326db58273


"Thierry" a écrit dans le message de news:

| Bonjour,
|
| Est-il possible, à partir d'Access (VBA), de copier les données d'un
| fichier .txt à la suite des données d'un autre fichier .txt ?
|
| (comme la commande Dos : more fichier1.txt >> fichier2.txt )
|
| Merci et bonne soirée.
| Thierry
|
|
Avatar
pgz
Bonsoir.

Tu devrais trouver ce dont tu as besoin dans les méthodes de la bibliothèque :
windows script host object model (IwshRuntimeLibrary)
et tous particulièrement la classe file system object.

voici 2 exemples :
Public Function fctLireFichierTxt(ByVal sPath As String) As String
'lit le fichier en entier dans une seule chaîne
Dim fso As IWshRuntimeLibrary.FileSystemObject
Dim fFile As IWshRuntimeLibrary.File
Dim ts As IWshRuntimeLibrary.TextStream
Dim s As String

Set fso = New IWshRuntimeLibrary.FileSystemObject
Set fFile = fso.GetFile(sPath)
Set ts = fFile.OpenAsTextStream(ForReading)

s= ts.ReadAll
fctLireFichierTxt = Replace(s, vbCrLf, "")


ts.Close
Set ts = Nothing
Set fFile = Nothing
Set fso = Nothing
End Function


'Ajouter une ligne :
Public Sub subAjouterLigneFichierTxt(ByVal sPath As String, ByVal sTexte As
String)
Dim fso As IWshRuntimeLibrary.FileSystemObject
Dim fFile As IWshRuntimeLibrary.File
Dim ts As IWshRuntimeLibrary.TextStream

Set fso = New IWshRuntimeLibrary.FileSystemObject
Set fFile = fso.GetFile(sPath)
Set ts = fFile.OpenAsTextStream(ForAppending)

ts.WriteLine sTexte

ts.Close
Set ts = Nothing
Set fFile = Nothing
Set fso = Nothing
End Sub


Bon courage
--
pgz
_____________________________