EbinPaulose
EbinPaulose

Reputation: 1139

How to create a text file using Macro in MS Office?

I have word document. I want to create a text file when opening this document. How can i create text file using macro?

Upvotes: 0

Views: 5466

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149295

Try this. You can create the text file in Document_Open() event

Private Sub Document_Open()
    Dim filesize As Integer
    Dim FlName As String

    FlName = "C:\Sample.Txt"

    '~~> get a free file handle
    filesize = FreeFile()

    '~~> Open your file
    Open FlName For Output As #filesize

    '~~> Export Text
    Print #filesize, "Hello World"
    Close #filesize
End Sub

Upvotes: 2

Related Questions