PC Review


Reply
Thread Tools Rate Thread

Can I use Word as a programmable text editor?

 
 
=?Utf-8?B?Umlja3N0ZXI=?=
Guest
Posts: n/a
 
      18th Sep 2007

Hi all

I use a flat file text editor - TextPad (Textpad.com) - to edit my text
files. But I've come to a situation where I need to programmatically load
some text files, search for a value and globally replace to a new value, then
save them out. Unfortunately, TextPad does not have a built-in fullly
functionable programming language. So I can't automate this with TextPad.

Can I use Word to load TXT files, do the edits, and save as TXT files in VBA?

By the way, anyone know of a text editor that has VBA as its built-in
programming language? Just curious.

Thanks
---
Rickster

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2V2aW4gQg==?=
Guest
Posts: n/a
 
      18th Sep 2007
The following SaveAs statement save the current file as an unformatted text
file

ActiveDocument.SaveAs FileName:="TextFile.txt", Fileformat:=wdFormatText
--
Kevin Backmann


"Rickster" wrote:

>
> Hi all
>
> I use a flat file text editor - TextPad (Textpad.com) - to edit my text
> files. But I've come to a situation where I need to programmatically load
> some text files, search for a value and globally replace to a new value, then
> save them out. Unfortunately, TextPad does not have a built-in fullly
> functionable programming language. So I can't automate this with TextPad.
>
> Can I use Word to load TXT files, do the edits, and save as TXT files in VBA?
>
> By the way, anyone know of a text editor that has VBA as its built-in
> programming language? Just curious.
>
> Thanks
> ---
> Rickster
>

 
Reply With Quote
 
=?Utf-8?B?SGFydmV5?=
Guest
Posts: n/a
 
      19th Sep 2007
Sure you can. This code is written by one of MVP's I just made a few minor
change.

'**************
Public Sub BatchReplaceAll()

Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long

PathToUse = "C:\" <-- write the correct path for the folder with .txt files

On Error Resume Next

FirstLoop = True

myFile = Dir$(PathToUse & "*.txt")

While myFile <> ""

'Open document
Set myDoc = Documents.Open(PathToUse & myFile)

If FirstLoop Then

Dialogs(wdDialogEditReplace).Show

FirstLoop = False

Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub

Else


With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With

End If


myDoc.Close SaveChanges:=wdSaveChanges

'Next file in folder

myFile = Dir$()

Wend

End Sub

'************
--
Best regards,
Harvey


"Rickster" wrote:

>
> Hi all
>
> I use a flat file text editor - TextPad (Textpad.com) - to edit my text
> files. But I've come to a situation where I need to programmatically load
> some text files, search for a value and globally replace to a new value, then
> save them out. Unfortunately, TextPad does not have a built-in fullly
> functionable programming language. So I can't automate this with TextPad.
>
> Can I use Word to load TXT files, do the edits, and save as TXT files in VBA?
>
> By the way, anyone know of a text editor that has VBA as its built-in
> programming language? Just curious.
>
> Thanks
> ---
> Rickster
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I set Word as the default text editor instead of Word Pad JIMROB Microsoft Word Document Management 1 28th Apr 2008 10:15 PM
Help with Word or Text Editor mattc66 via AccessMonster.com Microsoft Access External Data 0 7th Feb 2007 05:16 PM
DataGridView, how to programmable select text within a cell? LordHog@hotmail.com Microsoft C# .NET 0 3rd Aug 2005 09:08 PM
Using Word as text editor unavailable =?Utf-8?B?T3V0bG9va0dpcmw=?= Microsoft Outlook Discussion 4 18th May 2005 06:35 PM
word as text editor tony Microsoft Outlook Discussion 1 14th Jun 2004 09:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:25 PM.