Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 2nd, 2004, 01:59 PM
kud kud is offline
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default read text file to exact diff depts

I have a text file that have multiple division and dept num. I would like to import the information into excel workbook with different sheets named after the difference dept num in the text file. Ex 655, 643, 855, etc.... can excel macro read a text like that?

thanks
Julious

 
Old June 4th, 2004, 04:29 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

You could use File System Object to read the text file. You need to reference Microsoft Scripting Runtime. Below is a short example to read every line in the txt file:
***********************************
Dim FSO As New FileSystemObject
Dim FSTR As Scripting.TextStream
Private Sub Main()
Set FSTR = FSO.OpenTextFile("c:\myfile.txt")
    Do Until FSTR.AtEndOfStream
        ReadTextFile = FSTR.ReadLine
    Loop
End Sub
************************************

Let me know if you need more detail

Regards
Marnus
 
Old June 4th, 2004, 05:37 PM
kud kud is offline
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is example of the text file.
 I have a problem. I’m trying to import one text file that have multiple dept num ex. 655,632,654. Is it possible for excel to read a text more than once to get information needed.Ex



D,RLG,0632,003,21,0563130,3760-6004 ,7.10X11.2 ,ARDEBIL ,IV/RED ,053,0059326924,001,00564.00,00599.00,-00035.00,006,PMD ,01,0455899

D,RLG,0632,003,21,8051518,0715-4991 ,7.10RND ,CAIRO ,MIDNIGHT ,015,0059328116,001,00549.00,00519.00, 00030.00,006,PMU ,01,0538496

D,MCE,0652,017,12,8384133,B7497A ,SOFA ,1444-326 ,ROSE ,135,0036033126,001,00839.40,00999.00,-00159.60,016,PMD ,01,0080130

D,MCE,0652,017,12,8384190,T4787M ,SOFA ,1460-723 ,TAPESTRY ,124,0035994131,001,01169.00,01299.00,-00130.00,010,PMD ,01,0034787

D,MCE,0653,008,31,7913882,2580 ,WING ,1030-40 ,BURG ,002,0036026006,002,00499.00,00598.00,-00099.00,017,PMD ,01,0505867

D,MCE,0653,008,31,7913882,2580 ,WING ,1030-40 ,BURG ,125,0036031905,002,00499.00,00598.00,-00099.00,017,PMD ,01,0044041



Excel would need to read the text file and get all data by dept num and import to excel , create sheet for each dept num.



Quote:
quote:Originally posted by acdsky
 Hi

You could use File System Object to read the text file. You need to reference Microsoft Scripting Runtime. Below is a short example to read every line in the txt file:
***********************************
Dim FSO As New FileSystemObject
Dim FSTR As Scripting.TextStream
Private Sub Main()
Set FSTR = FSO.OpenTextFile("c:\myfile.txt")
    Do Until FSTR.AtEndOfStream
        ReadTextFile = FSTR.ReadLine
    Loop
End Sub
************************************

Let me know if you need more detail

Regards
Marnus





Similar Threads
Thread Thread Starter Forum Replies Last Post
read text file senthilreddy ASP.NET 1.0 and 1.1 Basics 1 December 19th, 2010 10:56 PM
Read and Edit the text file stuartlittle C# 3 February 26th, 2008 05:35 AM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.