Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Importing/Exporting text files and string editing

I have a flow chart in txt format. I can import the file into excel,
I select a semicolon delimeter as there are none in the file, and I
don't want excel messing up the spacing. I can export the file with
all the correct spacing, but I am not allowed to save formatting
(changing color, making text bold). So I since each of our jobs in
the file starts with MP, I want to replace those letters with ** if
the job has completed. A list of completed jobs will be on a seperate
worksheet. Each job name is not in its own cell, so I'll have to edit
the string. Any info on how to do this would be very helpfull. Also,
if there is a way to directly edit the file, or other suggestions,
that would be great as well.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Importing/Exporting text files and string editing

I figured it out, and I'm posting my code in case anybody else might
find it handy.

Sub Get_Text()

Dim strSourceFile As String, strOutFile As String, strInText As
String, strOutText As String
Dim strFront As String, strBack As String, strSearch As String
Dim lngInputFile As Long, lngOutputFile As Long, lngStringCalc As
Long
Dim intLength As Integer, intFoundAt As Integer
Dim intFoundText As Integer, intNumRows As Integer

strSourceFile = Application.GetOpenFilename("Text File
(*.txt),*.txt")
lngInputFile = FreeFile
Open strSourceFile For Input As lngInputFile

strOutFile = Left(strSourceFile, 12) & "out"
lngOutputFile = FreeFile

Open strOutFile For Output As lngOutputFile

intNumRows = Worksheets("Sheet1").UsedRange.Rows.Count

While Not EOF(lngInputFile)
Line Input #lngInputFile, strInText
Sheets("Sheet1").Range(Cells(1, "A"), Cells(intNumRows,
"A")).Select
For Each cell In Selection
strSearch = cell
intLength = Len(strInText)
intFoundAt = InStr(1, strInText, strSearch, vbTextCompare)
If intFoundAt 0 Then
lngStringCalc = intFoundAt - 1
strFront = Left(strInText, lngStringCalc)
lngStringCalc = intLength - intFoundAt - 7
strBack = Right(strInText, lngStringCalc)
strOutText = strFront & "**" & Right(strSearch, 6) &
strBack
strInText = strOutText
intFoundText = 1
End If
Next cell
If intFoundText 0 Then
Print #lngOutputFile, strOutText
intFoundText = 0
Else
Print #lngOutputFile, strInText
End If
Wend

End Sub



(Slick Willie) wrote in message . com...
I have a flow chart in txt format. I can import the file into excel,
I select a semicolon delimeter as there are none in the file, and I
don't want excel messing up the spacing. I can export the file with
all the correct spacing, but I am not allowed to save formatting
(changing color, making text bold). So I since each of our jobs in
the file starts with MP, I want to replace those letters with ** if
the job has completed. A list of completed jobs will be on a seperate
worksheet. Each job name is not in its own cell, so I'll have to edit
the string. Any info on how to do this would be very helpfull. Also,
if there is a way to directly edit the file, or other suggestions,
that would be great as well.

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
Importing, Editing and Exporting an EML file hshayh0rn Excel Discussion (Misc queries) 0 April 2nd 08 05:02 PM
Importing text-files GARY Excel Discussion (Misc queries) 6 December 13th 06 02:57 PM
Exporting and Importing Named cells to and from a text file clayton Excel Discussion (Misc queries) 0 January 18th 06 08:01 PM
Importing Text Files smith_gw Excel Discussion (Misc queries) 1 May 5th 05 10:42 PM
importing text files msweeney Excel Programming 3 September 24th 03 01:49 AM


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