Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

replace text in textstream before improting

Posted on 2003-03-29
4
Medium Priority
?
326 Views
Last Modified: 2011-09-20
how could i replace just certain words out of only the first line in the text file?

i just want to convert for instance "PH" to "Tel" and "NA" to "Company" etc

my current code is

Dim fso As New FileSystemObject
 Dim ts As TextStream
 Dim rowNo As Integer
 Dim i As Integer
 Dim xlRow() As String
 Dim xla As Excel.Application
 Dim xlw As Excel.Workbook
 Dim xls As Excel.Worksheet
 
 Set xla = CreateObject("Excel.Application")
 Set xlw = xla.Workbooks.Add
 Set xls = xlw.Sheets("Sheet1")
 rowNo = 1
 xla.Visible = False

 Set ts = fso.OpenTextFile("c:\test\file.txt")
 Do While ts.AtEndOfStream <> True
     xlRow = Split(ts.ReadLine, ",", -1, vbTextCompare)
     For i = 0 To UBound(xlRow)
         xlRow(i) = Replace(xlRow(i), Chr(34), "")
         xls.Cells(rowNo, i + 1) = xlRow(i)
     Next i%
     rowNo = rowNo + 1
 Loop
 ts.Close
 
 xlw.SaveAs ("c:\test\file.xls")
 xla.Quit
 Set xla = Nothing
0
Comment
Question by:Marcusw
  • 2
4 Comments
 
LVL 4

Expert Comment

by:iozturk
ID: 8232452
Set ts = fso.OpenTextFile("c:\test\file.txt")
ts.skipline
Do While ts.AtEndOfStream <> True
    xlRow = Split(ts.ReadLine, ",", -1, vbTextCompare)
    For i = 0 To UBound(xlRow)
        xlRow(i) = Replace(xlRow(i), Chr(34), "")
        xls.Cells(rowNo, i + 1) = xlRow(i)
    Next i%
    rowNo = rowNo + 1
Loop
ts.Close
0
 
LVL 4

Expert Comment

by:iozturk
ID: 8232460
Set ts = fso.OpenTextFile("c:\test\file.txt")
ts.skipline
Do While ts.AtEndOfStream <> True
    xlRow = Split(ts.ReadLine, ",", -1, vbTextCompare)
    For i = 0 To UBound(xlRow)
        xlRow(i) = Replace(xlRow(i), Chr(34), "")
        xls.Cells(rowNo, i + 1) = xlRow(i)
    Next i%
    rowNo = rowNo + 1
Loop
ts.Close
0
 
LVL 12

Accepted Solution

by:
jyokum earned 1000 total points
ID: 8232689
dim strLine as String
dim blnFirstLine as Boolean
blnFirstLine = True

Set ts = fso.OpenTextFile("c:\test\file.txt")
Do While ts.AtEndOfStream <> True
   strLine = ts.ReadLine
   If blnFirstLine then
      strLine = Replace(strLine,"PH","Tel")
      strLine = Replace(strLine,"NA","Company")
      blnFirstLine = False
   End If
   xlRow = Split(strLine, ",", -1, vbTextCompare)
   For i = 0 To UBound(xlRow)
       xlRow(i) = Replace(xlRow(i), Chr(34), "")
       xls.Cells(rowNo, i + 1) = xlRow(i)
   Next i%
   rowNo = rowNo + 1
Loop
ts.Close
0
 

Expert Comment

by:CleanupPing
ID: 8531344
Hi Marcusw,
This old question (QID 20567698) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question