How open notepad.exe and write text line by line via excel vba?
"geniusideas" wrote:
At the end of my code I need to open notepad.exe and
write text line by line. How to do with excel vba.
No need to run notepad.exe. See the following paradigm.
FYI: The macro writes the same line twice two different ways to demonstrate
the difference. I use the Print...myLine method in order to have complete
control over spacing.
Sub makeTextFile()
Const myDir = "C:\temp\"
Const myOutFile = "temp.txt"
Dim fnOut As Long
Dim n As Long, myLine As String, myOutPath As String
myOutPath = myDir & myOutFile
fnOut = FreeFile
Open myOutPath For Output Access Write As #fnOut
For n = 1 To 10
myLine = "Line " & n & Format(Timer(), " 0.000000")
Print #fnOut, myLine
Print #fnOut, "Line "; n; Format(Timer(), " 0.000000")
Next
n = n - 1
Close
MsgBox "done" & vbNewLine & n & " lines"
End Sub
|