473,383 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Excel Spreadsheet

Hi all,
I am trying to write a vb script to export data from txt files in a particular folder in
each row in excel spreadsheet.

the data in a.txt is

1
2
3
4
5

the data in b.txt is

6
7
8
9
10

The resultant excel file should have data (each text file in 1 row with data in seperate columns)

1 2 3 4 5
6 7 8 9 10

The code I have is as below. Can you please help me with formatting the data properly.

Dim oFSO
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

Const Folder = "C:\temp\"
Dim oGF
Set oGF = oFSO.GetFolder(Folder)

Dim oTF

Set fso = CreateObject("Scripting.FileSystemObject")

'********* CREATES AN EXCEL SPREADSHEET***************************
Const ADS_SCOPE_SUBTREE = 2
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
' objExcel.Cells(1, 1).Value = "PC-NAME"
'************************************************* ********************

X = 2 ' Sets the X value
Y = 1 ' Sets the Y value

'***** READS LIST OF PC'S TO INVENTORY ******************************
For Each oTF In oGF.Files
If(Right(oTF.Name,3)) = "txt" Then
set bF = fso.opentextFile(Folder & oTF.Name) 'read list of computers
Do While bF.AtEndofStream <> True
strComputer = bF.readline
'************************************************* *****************

on error resume next

objExcel.Cells(x, y).Value = strComputer

'y = y + 1
x = x + 1
Loop
bF.close
End If
Next
Jan 4 '07 #1
1 1485
Killer42
8,435 Expert 8TB
... The code I have is as below. Can you please help me with formatting the data properly.
Can you show us what results you are getting now?

Just off the top of my head, adjusting the code like this might help a little. I've just modified things slightly at the end of the loop. (I didn't bother posting all the code before the loop)
Expand|Select|Wrap|Line Numbers
  1. ...
  2. ' ***** READS LIST OF PC'S TO INVENTORY ******************************
  3. For Each oTF In oGF.Files
  4.   If(Right(oTF.Name,3)) = "txt" Then
  5.     set bF = fso.opentextFile(Folder & oTF.Name) 'read list of computers
  6.     Do While bF.AtEndofStream <> True
  7.       strComputer = bF.readline
  8. ' ******************************************************************
  9.  
  10.       on error resume next
  11.  
  12.       objExcel.Cells(x, y).Value = strComputer
  13.  
  14.       x = x + 1
  15.     Loop
  16.     bF.close
  17.     y = y + 1
  18.     x = 2
  19.   End If
  20. Next
Jan 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Phil Powell | last post by:
What would one best recommend to parse an existing Excel spreadsheet (was done in Excel 97 or 2000 not sure to be honest)? I am looking for the most practical way of parsing an existing...
0
by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to...
0
by: Rich Wallace | last post by:
Hello all, Looking for suggestions and tips if possible. I have an application running on a file server that utilizes the FileSystemWatcher to trap when any Excel files are saved by a user. I...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
3
by: Scott M. Lyon | last post by:
I'm trying to figure out a way to export data (actually the result of a Stored Procedure call from SQL Server) into a specified Excel spreadsheet format. Currently, I have the data read into a...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
3
by: S_K | last post by:
Hi, I have a problem when I try to save a .CSV file from an ASP.NET web page and the client has Excel open already. The symptoms are: 1) The web page is currently displaying the Excel...
0
by: jwmaiden | last post by:
Have an application that opens up a webbrowser control to display data in an Excel spreadsheet (using VB.NET in VS 2005). No problem with opening the spreadsheet or displaying the data, but I'm...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.