Paste Data To WordPad TXT File

  • Thread starter Thread starter DaveM
  • Start date Start date
D

DaveM

I have a fairly simple macro that copies data from a few sheets and
consolidates it (via paste) into one sheet. I know what to copy this
consoldiates data in this sheet (say A1:G65) and I want to copy it and paste
it into a wordpad document file (NewData.txt) and save the txt file once it
is pasted so i can then do some different work with the txt file.

How do i call these tasks from within an excel macro?

thx
davem
 
You can't automate WordPad or NotePad, unless you use the dreaded SendKeys
method. It would be much easier to use VB's own file input/output functions
to write the text file. Something along the lines of

Sub WriteToTextFile()
Dim FName As Variant
Dim FNum As Integer
Dim R As Range

FName = Application.GetSaveAsFilename(filefilter:="Text Files
(*.txt),*.txt")
If FName = False Then
' user cancelled
Exit Sub
End If

FNum = FreeFile()
Open FName For Output Access Write As #FNum
For Each R In Range("A1:A10")
Print #FNum, R.Text
Next R
Close #FNum
End Sub

See also www.cpearson.com/Excel/ImpText.aspx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top