Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Creating properly formatted text file from vbscript using excel data

I have an excel spreadsheet named test.xls with A1:B2 populated this way:

A B
~ ~
1 2
3 4

What I want to do from VBScript is copy that data and export it to a tab
deliminated text file.

For example, I can create a document called hello.txt and in it, it would
have
1 2
3 4


I just started playing around with this and have the following so far:
'================================
Dim Xl
Dim myData

myData=""

Set Xl = CreateObject("Excel.Application")
Xl.Workbooks.Open("C:\test.xls")
Xl.Sheets("Sheet1").Select

for each r in Xl.Range("A1","B2")
myData = myData & r.value & vbTab
next

msgbox myData

Set Xl = Nothing
'================================

I haven't created the text file yet (that's trivial). The problem is that
the output comes as follows:

1 2 3 4




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Creating properly formatted text file from vbscript using excel data

You can save an excel file as tab delimited after you open it.


ChDir "C:\WINDOWS\Desktop"
ActiveWorkbook.SaveAs FileName:="C:\WINDOWS\Desktop\Blank Excel1.txt", _
FileFormat:=xlText, CreateBackup:=False




"msnews.microsoft.com" wrote in message
...
I have an excel spreadsheet named test.xls with A1:B2 populated this way:

A B
~ ~
1 2
3 4

What I want to do from VBScript is copy that data and export it to a tab
deliminated text file.

For example, I can create a document called hello.txt and in it, it would
have
1 2
3 4


I just started playing around with this and have the following so far:
'================================
Dim Xl
Dim myData

myData=""

Set Xl = CreateObject("Excel.Application")
Xl.Workbooks.Open("C:\test.xls")
Xl.Sheets("Sheet1").Select

for each r in Xl.Range("A1","B2")
myData = myData & r.value & vbTab
next

msgbox myData

Set Xl = Nothing
'================================

I haven't created the text file yet (that's trivial). The problem is that
the output comes as follows:

1 2 3 4






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Creating properly formatted text file from vbscript using excel data

Thanks Mike. The problem is that I have 10 worksheets in the workbook and
want to save each worksheet with a separate name (use the sheet name for
file name and add .txt). Also each worksheet has extra rows and columns
surrounding the actual data I want to copy to the text file.

I figured it would be easier to just extract the data from vbscript and
creating the text file dynamically, but if there is a way to save a
worksheet as a tab delimited file, that would be great. I can just copy the
range of data to a new worksheet and save that worksheet.


"Mike Tomasura" wrote in message
...
You can save an excel file as tab delimited after you open it.


ChDir "C:\WINDOWS\Desktop"
ActiveWorkbook.SaveAs FileName:="C:\WINDOWS\Desktop\Blank Excel1.txt",

_
FileFormat:=xlText, CreateBackup:=False




"msnews.microsoft.com" wrote in message
...
I have an excel spreadsheet named test.xls with A1:B2 populated this

way:

A B
~ ~
1 2
3 4

What I want to do from VBScript is copy that data and export it to a tab
deliminated text file.

For example, I can create a document called hello.txt and in it, it

would
have
1 2
3 4


I just started playing around with this and have the following so far:
'================================
Dim Xl
Dim myData

myData=""

Set Xl = CreateObject("Excel.Application")
Xl.Workbooks.Open("C:\test.xls")
Xl.Sheets("Sheet1").Select

for each r in Xl.Range("A1","B2")
myData = myData & r.value & vbTab
next

msgbox myData

Set Xl = Nothing
'================================

I haven't created the text file yet (that's trivial). The problem is

that
the output comes as follows:

1 2 3 4








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
Line Chart from office 2003.xls not formatted properly in 2007 tj Excel Discussion (Misc queries) 0 December 9th 09 10:31 PM
CSV file doesn't save "xEy" style number as text formatted data [email protected] Excel Discussion (Misc queries) 1 July 30th 08 06:03 PM
Converting formatted text into a txt file Marc Excel Discussion (Misc queries) 1 June 21st 07 04:00 PM
Reading in poorly formatted text file Some Dude Excel Discussion (Misc queries) 1 February 11th 07 10:24 PM
Need help with creating a text file via excel [email protected] Excel Worksheet Functions 3 June 13th 05 02:49 PM


All times are GMT +1. The time now is 12:41 AM.

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"