Tu mets ton chemin en dur (à éviter)
'Module1: Public Const CSIDL_DESKTOPDIRECTORY = 16 ' Desktop folder ([user] profile) Public Type shiEMID cb As Long abID As Byte End Type Public Type ITEMIDLIST mkid As shiEMID End Type Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function GetSpecialfolder(CSIDL As Long) As String Dim IDL As ITEMIDLIST Dim sPath As String Dim iReturn As Long iReturn = SHGetSpecialFolderLocation(100, CSIDL, IDL) If iReturn = NOERROR Then sPath = Space(512) iReturn = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) GetSpecialfolder = sPath Exit Function End If GetSpecialfolder = "" End Function
Private Sub Command1_Click() Me.Caption = GetSpecialfolder(CSIDL_DESKTOPDIRECTORY) Me.Caption = Me.Caption & "\Fichier.txt" 'Crée et inscrit des données dans le fichier.txt sur le bureau de l'utilisateur actuel 'Si le Fichier.txt existe déjà il écrit les données à la suite Open Form1.Caption For Append As #1 Print #1, "Ligne de texte 1" Print #1, "Ligne de texte 2" 'etc... Close End Sub
Open "C:\Sujet.txt" For Append As #1 Print #1, "origine du film: " & text1.text Print #1, "durée: " & A2.text 'etc... Close
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOpen Me.Caption For Append As #1 Print #1, "Ligne de texte 1" Print #1, "Ligne de texte 2" 'etc... Close
Open "C:\Sujet.txt" For Append As #1 Print #1, "origine du film: " & text1.text
Open aslam.Caption For Output As 1 Write #1, "origine du film: " & text1.text
"Origine du film: francais"
Dim FID As Integer: FID = FreeFile Open "c:\temp\fichier.txt" For Output As #FID Print #FID, "hello world" Close #FID
Users devient Utilisateurs et Desktop devient Bureau