Member Avatar for breezyy

Hey guys,
Do you know of any codes that automatically creates a file? Whenever I use open/get etc, I need to manually create the file, or otherwise I get a bad file name error.
Thanks in advance

what kind of file u need to create? text file or other?

Try this code

Dim Fso As New FileSystemObject
Dim Fl As TextStream
Dim fName as String

fName = App.Path & "\" & "MyFile.txt"

If Dir(fName) <> "" Then
 If MsgBox("File Exists.OverWrite?",vbYesNo,"FILE EXISTS")=vbYes Then
      Set Fl = Fso.CreateTextFile(fName, True)
 Else
      GoTo ExitPoint
  End If
Else
 'Here True/False is to Overwrite/Not if a file already exists
 'by the name given in fName.
 Set Fl = Fso.CreateTextFile(fName, True)
End If

 Fl.Close

ExitPoint:
 Set Fl = Nothing
 Set FSO = Nothing

Regards
Shaik Akthar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.