Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Editing text file

Mornin' all,

I need to open a text file, then replace all occurences of
certain symbols with either nothing or a line return.

I really don't know where to start on this one, has anyone
got some pointers or code that would help me?

Thanks very much,
Foss
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Editing text file

Hi Foss,
If that can help you:

Sub UpDateTxtFile()
Dim FSO As Object, File As Object, Contents As String
Set FSO = CreateObject("Scripting.FileSystemObject")

' Create file to test example:
Set File = FSO.CreateTextFile("c:\examplefile.txt")
Contents = "A quick example of the ReadAll method !!!"
Contents = Contents & vbCrLf
Contents = Contents & "New line for this example !!!"
File.Write Contents
File.Close

' Replacement routine
Const TxtFullPath As String = "c:\examplefile.txt"
Dim ReadFile As Object
Set ReadFile = FSO.OpenTextFile(TxtFullPath, 1, False)
Contents = ReadFile.ReadAll
ReadFile.Close: Set ReadFile = Nothing
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = False
.Pattern = "[!" & vbCrLf & "]"
Contents = .Replace(Contents, "")
End With
Set File = FSO.CreateTextFile(TxtFullPath)
File.Write Contents
File.Close
Set File = Nothing: Set FSO = Nothing
End Sub

Regards,
MP

"Foss" a écrit dans le message de
...
Mornin' all,

I need to open a text file, then replace all occurences of
certain symbols with either nothing or a line return.

I really don't know where to start on this one, has anyone
got some pointers or code that would help me?

Thanks very much,
Foss



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Editing text file

Hi there MP

Thanks, that's great! One more question though, how can I replace a space with a linefeed

I've tried using the Chr(10) thing but it doesn't seem to work

Cheers
Fos


----- Michel Pierron wrote: ----

Hi Foss
If that can help you

Sub UpDateTxtFile(
Dim FSO As Object, File As Object, Contents As Strin
Set FSO = CreateObject("Scripting.FileSystemObject"

' Create file to test example
Set File = FSO.CreateTextFile("c:\examplefile.txt"
Contents = "A quick example of the ReadAll method !!!
Contents = Contents & vbCrL
Contents = Contents & "New line for this example !!!
File.Write Content
File.Clos

' Replacement routin
Const TxtFullPath As String = "c:\examplefile.txt
Dim ReadFile As Objec
Set ReadFile = FSO.OpenTextFile(TxtFullPath, 1, False
Contents = ReadFile.ReadAl
ReadFile.Close: Set ReadFile = Nothin
With CreateObject("VBScript.RegExp"
.Global = Tru
.IgnoreCase = Fals
.Pattern = "[!" & vbCrLf & "]
Contents = .Replace(Contents, ""
End Wit
Set File = FSO.CreateTextFile(TxtFullPath
File.Write Content
File.Clos
Set File = Nothing: Set FSO = Nothin
End Su

Regards
M

"Foss" a écrit dans le message d
..
Mornin' all
I need to open a text file, then replace all occurences o

certain symbols with either nothing or a line return
I really don't know where to start on this one, has anyon

got some pointers or code that would help me
Thanks very much

Fos




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Editing text file

Hi Foss,
in your procedure, test with:
.Pattern = "[ ]"
Contents = .Replace(Contents, Chr(10))

MP

"Foss" a écrit dans le message de
...
Hi there MP,

Thanks, that's great! One more question though, how can I replace a space with a

linefeed?

I've tried using the Chr(10) thing but it doesn't seem to work.

Cheers,
Foss


----- Michel Pierron wrote: -----

Hi Foss,
If that can help you:

Sub UpDateTxtFile()
Dim FSO As Object, File As Object, Contents As String
Set FSO = CreateObject("Scripting.FileSystemObject")

' Create file to test example:
Set File = FSO.CreateTextFile("c:\examplefile.txt")
Contents = "A quick example of the ReadAll method !!!"
Contents = Contents & vbCrLf
Contents = Contents & "New line for this example !!!"
File.Write Contents
File.Close

' Replacement routine
Const TxtFullPath As String = "c:\examplefile.txt"
Dim ReadFile As Object
Set ReadFile = FSO.OpenTextFile(TxtFullPath, 1, False)
Contents = ReadFile.ReadAll
ReadFile.Close: Set ReadFile = Nothing
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = False
.Pattern = "[!" & vbCrLf & "]"
Contents = .Replace(Contents, "")
End With
Set File = FSO.CreateTextFile(TxtFullPath)
File.Write Contents
File.Close
Set File = Nothing: Set FSO = Nothing
End Sub

Regards,
MP

"Foss" a écrit dans le message de
...
Mornin' all,
I need to open a text file, then replace all occurences of

certain symbols with either nothing or a line return.
I really don't know where to start on this one, has anyone

got some pointers or code that would help me?
Thanks very much,

Foss






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
i cant open a file for editing? caroline New Users to Excel 1 January 30th 10 07:49 PM
file locked for editing davehunter64 Excel Worksheet Functions 0 June 13th 08 11:20 AM
Editing Text and file location for Hyperlinks forest8 Excel Worksheet Functions 1 May 17th 08 11:57 AM
Trying to Open Excel File, But its says file is locked for editing Smeeta Geary Excel Discussion (Misc queries) 1 September 20th 05 01:28 PM
Copying the Editing in one file to Another opened XLS file Ahmad Excel Worksheet Functions 1 May 27th 05 02:04 PM


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