![]() |
#2
|
||||
|
||||
![]()
This is fairly straightforward. You cannot read from Notepad, however you can read from a text file created by Notepad. Assuming the space between the columns in the list is a tab character (as copied from Excel) then the following will find the first part in the body of the document and replace it with the second. If there are other areas to process, you will have to loop through the story ranges to use this code.
Code:
Sub ReplaceFromTextFile() Dim oRng As Range Dim sFindText As String, sReplacement As String Dim iNum As Integer Dim sData As String Dim vData As Variant Const sName As String = "C:\Path\Forums\list.txt" iNum = FreeFile() Open sName For Input As #iNum While Not EOF(iNum) Line Input #iNum, sData vData = Split(sData, Chr(9)) Set oRng = ActiveDocument.Range sFindText = vData(0) sReplacement = vData(1) With oRng.Find .ClearFormatting .Replacement.ClearFormatting Do While .Execute(FindText:=sFindText, _ MatchWholeWord:=True, _ MatchWildcards:=False, _ Forward:=True, _ Wrap:=wdFindStop) = True oRng.Text = sReplacement oRng.Collapse wdCollapseEnd Loop End With Wend lbl_Exit: Set oRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word does not stop at the set tab, but it keeps forever on the same line like it would in Notepad. | danvina@gmail.com | Word | 2 | 01-16-2019 02:33 PM |
![]() |
k31453 | Excel | 1 | 04-18-2017 07:24 AM |
Notepad Terminal Font in Word? | Elap | Word | 6 | 05-24-2016 03:25 AM |
![]() |
gsrikanth | Office | 3 | 02-25-2012 02:47 PM |
![]() |
WASplawn | Word | 6 | 09-27-2011 10:17 AM |