Excel to notepad




Sub TestNotePad()

    '// The range to copy - written freehand so change as needed
    Range("A1:B55").Copy
   
    '// Start Notepad with focus
    Shell "notepad.exe", vbNormalFocus
   
    '// Send the standard CTRL+V. Pastes to the
    '// active window (Notepad, hopefully)
    SendKeys "^V"

    '// Back to the top of the file
    SendKeys "^{HOME}"
   
End Sub

-------------------


cebu1014
Author Commented: 2013-05-22
I got it to work using your above routine as a guide. I removed some of the lines though and added  TRUE at end of sendkeys command in order to get it to work.

Sub CopyToNotepad()
   
   
     Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy

 
    Shell "Notepad C:\Users\mw1\my Documents\abc.csv", vbNormalFocus


   
    SendKeys "^a", True
    SendKeys "{ENTER}", True
SendKeys ("^{HOME}"), True
SendKeys "^v", True
End Sub

----------------------------------------------------------
The complete VBA code:

Sub ExportToNotepad()
Dim wsData As Variant
Dim myFileName As String
Dim FN As Integer
Dim p As Integer, q As Integer
Dim path As String
Dim myString As String
Dim lastrow As Long, lastcolumn As Long

lastrow = Sheets(“sheet1”).Range(“A” & Rows.Count).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
path = “C:\Users\takyar\Desktop\sudhakar\”

For p = 1 To lastcolumn
wsData = ActiveSheet.Cells(1, p).Value
If wsData = “” Then Exit Sub
myFileName = wsData
myFileName = myFileName & “.txt”
myFileName = path & myFileName
‘MsgBox myFileName
For q = 2 To lastrow
myString = myString & ” ” & Cells(q, p)

FN = FreeFile
Open myFileName For Output As #FN
Print #FN, myString
Close #FN
Next q
myString = “”
Next p

End Sub

Comments

Popular posts from this blog

number format

send Mail by outlook from excel sheet

Find and copy the data