Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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 06:54 PM.

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

About Us

"It's about Microsoft Excel"