Reputation: 1139
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
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