View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
moon[_6_] moon[_6_] is offline
external usenet poster
 
Posts: 43
Default Writing to Notepad from VBA


'Method 1.
Public Sub Data2TxtFile1()
Dim fso, f
Dim wb As Workbook, ws As Worksheet
Dim textString As String
Const forWriting = 2
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\testfile.txt", forWriting, False)
ws.Activate
textString = ws.Cells(1, 1).Value
f.WriteLine textString
f.Close
Set f = Nothing
Set fso = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub

'Method 2.
Public Sub Data2TxtFile2()
Dim wb As Workbook, ws As Worksheet
Dim textString As String
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
ws.Activate
textString = ws.Cells(2, 1).Value
Open "C:\testfile.txt" For Append As #1
Write #1, textString
Close #1
Set ws = Nothing
Set wb = Nothing
End Sub




"stuart" schreef in bericht
...
It can write to the text editor and after it's finished I can then see
what
has been written. The editor doesn't need to be open during the task.

Thanks.

"NickHK" wrote:

Stuart,
What I mean, you you have to write an open text editor program directly
or
is creating a text file on the system that you later open in Textpad (or
whatever) OK ?
The second option is prettyy straightforward ; check out the Open
statement
in VBA help.
The first option would be more convoluted, unless it's Word.

NickHK

"stuart"
...
NickHK,

It can write to any text editor. But I only have Notepad, Wordpad and
Word
on my PC.

Thanks.

"NickHK" wrote:

Stuart,
Do you mean actually write to the Notepad app, or just write a text
file
?

NickHk

"stuart"
...

Hi,

I'm writing a macro using VBA in Excel and to get the output from
the
macro
to be written in Notepad rather than an Excel worksheet. How do I do
this,
if
it's at all possible?

Thanks.