Sunday, March 26, 2017

Macro to Create Text File

'---------------------------Macro to Create Text File-------------------------------'
Sub createtextfile()

Dim fso As New FileSystemObject
Dim txtfl As TextStream

'---------------------------Creating text file and writing---------------------------'

Set txtfl = fso.createtextfile(Environ("Userprofile") & "\Desktop\VBA Classs\Macro in Text File\createmacrofile.txt", True)

txtfl.Write "Created on:" & Now() & vbNewLine
txtfl.WriteLine "Macro Craeted by:" & Environ("UserName")
txtfl.WriteBlankLines (2)
txtfl.Write "Data Starts from here:-" & vbNewLine
txtfl.Close

End Sub

No comments:

Post a Comment

*INTERVIEW QUESTIONS

* Ques 01. What is the difference between ByVal and ByRef and which is default ? Ans-  ByRef : If you pass an argument by reference when...