buongiorno, come da titolo vorrei creare un file txt con l'oggetto fso però c'è qualcosa che non va. Ho usato un goto per uscire dalla sub :
ma scusate, dopo aver confrontato i vari nomi , perché non crea il file ? cosa mi sfugge ?
grazie
Visual Basic:
Private Sub CommandButton2_Click()
Dim FSO As Object
Dim NEWFILE As Object
Dim NOME_FILE As String
Dim Elenco As Object
Dim Elemento As Variant
Dim nome As String
Dim I As Long
Dim UR As Long
Set FSO = CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set Elenco = FSO.getfolder("C:\Users\***\Desktop\test\")
UR = Cells(Rows.Count, 1).End(xlUp).Row
NOME_FILE = "nuovo.txt"
For Each Elemento In Elenco.Files
nome = nome & vbCrLf & Elemento.Name
If Elemento.Name = NOME_FILE Then
MsgBox "FILE ESISTENTE !"
GoTo ESCI
End If
Debug.Print Elemento.Name & " - "; NOME_FILE
Next Elemento
ESCI:
MsgBox ("ELENCO DEI FILE PRESENTI : " & vbCrLf & "--------------------------------" & vbCrLf & nome)
Exit Sub
Set NEWFILE = FSO.CREATETEXTFILE("C:\Users\***\Desktop\test\" & NOME_FILE)
For I = 2 To UR
NEWFILE.WRITELINE Cells(I, 1)
Next I
End Sub
ma scusate, dopo aver confrontato i vari nomi , perché non crea il file ? cosa mi sfugge ?
grazie
