Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
i cant open a file for editing? | New Users to Excel | |||
file locked for editing | Excel Worksheet Functions | |||
Editing Text and file location for Hyperlinks | Excel Worksheet Functions | |||
Trying to Open Excel File, But its says file is locked for editing | Excel Discussion (Misc queries) | |||
Copying the Editing in one file to Another opened XLS file | Excel Worksheet Functions |