Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Writing to Notepad from VBA

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Writing to Notepad from VBA

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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Writing to Notepad from VBA

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.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Writing to Notepad from VBA

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.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Writing to Notepad from VBA

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.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Writing to Notepad from VBA

Stuart,
If the editor is not open, you can't write to it.
So, write to a file:

Dim FF As Long
FF = FreeFile
Open "C:/TextFile.txt" For Output As #FF
Print #FF, "Some Text"
'or a Value from the WS
Print #FF, Range("A1").Value
Close #FF

NickHK

"stuart" ...
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.








  #7   Report Post  
Posted to microsoft.public.excel.programming
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.








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Writing to Notepad from VBA

Both writing a text file and opening that text file are quite simple:

To write to text:

Sub StringToTextFile(ByVal txtFile As String, _
ByVal strString As String)

Dim hFile As Long

hFile = FreeFile

Open txtFile For Output As hFile
'Write #hFile, strString 'this will make start- and end quotes
Print #hFile, strString;
Close #hFile

End Sub


To open the text file:

Sub OpenAsText(strPath As String)

Dim lRetVal As Long 'can do without this

On Error GoTo CANTOPEN

If bFileExists(strPath) Then
lRetVal = Shell("write" & " " & """" & strPath & """", 1)
Else
MsgBox "There is no valid file path supplied", , "opening text file"
End If

Exit Sub
CANTOPEN:

MsgBox "Could not open" & _
vbCrLf & vbCrLf & _
strPath, , "opening text file"

End Sub

Function bFileExists(ByVal sFile As String) As Boolean

Dim lAttr As Long

On Error Resume Next
lAttr = GetAttr(sFile)
bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0)
On Error GoTo 0

End Function


RBS


"stuart" wrote in message
...
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to notepad file Jeff Excel Discussion (Misc queries) 2 October 23rd 06 03:16 AM
Is there a way to do this without using notepad? Necessitysslave Excel Programming 3 February 15th 06 07:49 PM
NotePad OldCCN Excel Programming 1 July 7th 04 07:40 PM
notepad in excel Mohan[_2_] Excel Programming 1 August 29th 03 03:08 PM
opening and writing into notepad peter Excel Programming 1 August 15th 03 07:09 PM


All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"