Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help saving a select to a text file

How do I programmatically extract data from a worksheet (a range, not the
entire sheet) to a text file?

What I am doing now is selecting the data I want with my mouse and copying
it. I then paste it to notepad and save it. I would like to do this
automatically from an external script, preferably VBScript.


Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help saving a select to a text file

In code: create a new workbook, copy the range to the new workbook, saveas a
text file.

Dim rng as Range
set rng = Range("A1").CurrentRegion
Workbooks.Add
rng.copy Destination:=Activesheet.Range("A1")
Activeworkbook.SaveAs Filename:="C:\data\mytext.csv, _
Fileformat:=xlCSV
Activeworkbook.close Savechanges:=False

--
Regards,
Tom Ogilvy


msnews.microsoft.com wrote in message
...
How do I programmatically extract data from a worksheet (a range, not the
entire sheet) to a text file?

What I am doing now is selecting the data I want with my mouse and copying
it. I then paste it to notepad and save it. I would like to do this
automatically from an external script, preferably VBScript.


Thanks in advance.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Help saving a select to a text file

Thanks Tom.

Using your code, I am able to create the file, but there is nothing in it.

I have data in A1, but it doesn't get copied to the new worksheet.

Any ideas?




"Tom Ogilvy" wrote in message
...
In code: create a new workbook, copy the range to the new workbook, saveas

a
text file.

Dim rng as Range
set rng = Range("A1").CurrentRegion
Workbooks.Add
rng.copy Destination:=Activesheet.Range("A1")
Activeworkbook.SaveAs Filename:="C:\data\mytext.csv, _
Fileformat:=xlCSV
Activeworkbook.close Savechanges:=False

--
Regards,
Tom Ogilvy


msnews.microsoft.com wrote in message
...
How do I programmatically extract data from a worksheet (a range, not

the
entire sheet) to a text file?

What I am doing now is selecting the data I want with my mouse and

copying
it. I then paste it to notepad and save it. I would like to do this
automatically from an external script, preferably VBScript.


Thanks in advance.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help saving a select to a text file

As written, the code assumes, that when you run it, the worksheet with the
data is the activesheet and the data starts in Cell A1.
it creates a reference (rng) to the data starting in the upperleft corner
of the activesheet
it creates a new workbook
if copies the original data to cell A1 of the activesheet in the new
workbook
it saves the new workbook as a csv file
it closes the new workbook

Beyond that, it should work.
--
Regards,

"msnews.microsoft.com" wrote in message
...
Thanks Tom.

Using your code, I am able to create the file, but there is nothing in it.

I have data in A1, but it doesn't get copied to the new worksheet.

Any ideas?




"Tom Ogilvy" wrote in message
...
In code: create a new workbook, copy the range to the new workbook,

saveas
a
text file.

Dim rng as Range
set rng = Range("A1").CurrentRegion
Workbooks.Add
rng.copy Destination:=Activesheet.Range("A1")
Activeworkbook.SaveAs Filename:="C:\data\mytext.csv, _
Fileformat:=xlCSV
Activeworkbook.close Savechanges:=False

--
Regards,
Tom Ogilvy


msnews.microsoft.com wrote in message
...
How do I programmatically extract data from a worksheet (a range, not

the
entire sheet) to a text file?

What I am doing now is selecting the data I want with my mouse and

copying
it. I then paste it to notepad and save it. I would like to do this
automatically from an external script, preferably VBScript.


Thanks in advance.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help saving a select to a text file

Just to be sure, change
Workbooks.Add

to

Workbooks.Add Template:=xlWBATWorksheet

to make sure you create a single sheet workbook.

--
Regards,
Tom Ogilvy

"msnews.microsoft.com" wrote in message
...
Thanks Tom.

Using your code, I am able to create the file, but there is nothing in it.

I have data in A1, but it doesn't get copied to the new worksheet.

Any ideas?




"Tom Ogilvy" wrote in message
...
In code: create a new workbook, copy the range to the new workbook,

saveas
a
text file.

Dim rng as Range
set rng = Range("A1").CurrentRegion
Workbooks.Add
rng.copy Destination:=Activesheet.Range("A1")
Activeworkbook.SaveAs Filename:="C:\data\mytext.csv, _
Fileformat:=xlCSV
Activeworkbook.close Savechanges:=False

--
Regards,
Tom Ogilvy


msnews.microsoft.com wrote in message
...
How do I programmatically extract data from a worksheet (a range, not

the
entire sheet) to a text file?

What I am doing now is selecting the data I want with my mouse and

copying
it. I then paste it to notepad and save it. I would like to do this
automatically from an external script, preferably VBScript.


Thanks in advance.








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
Saving Text File Olan Gotcher Excel Discussion (Misc queries) 1 July 15th 06 10:20 PM
Text file saving, setting file origin mauddib Excel Discussion (Misc queries) 0 May 25th 06 02:50 PM
saving a text file to excel bullseye Excel Worksheet Functions 3 May 4th 06 01:07 AM
Saving sheet to text file Rob Excel Discussion (Misc queries) 4 December 9th 05 09:55 PM
saving an excel file as text without text in quotes John Excel Discussion (Misc queries) 2 December 6th 05 06:20 PM


All times are GMT +1. The time now is 07:23 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"