#1
|
|||
|
|||
Need help to get data from notepad to word
Hi Guys
I am back... I need the macro which helps to get data from notepad or excel to replace in word file. I have the data in notepad or excel in two columns as follows, seq-0001 seq-XX0001 seq-0002 seq-XX0010 sup-0010 sup-XX0022 fig-0022 fig-XX0012 etc..... The first column values found in the word file without any specific order and found more than once in also in several places. What i need to do is, if i found any first column value in word that needs to be changed as per the second column's respective values vice vara. Please check and advise on this.... |
#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 |
#3
|
|||
|
|||
Thanks a lot!!! @gmayor
This one is perfect...... |
|
Similar Threads | ||||
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 |
Data format to Notepad | k31453 | Excel | 1 | 04-18-2017 07:24 AM |
Notepad Terminal Font in Word? | Elap | Word | 6 | 05-24-2016 03:25 AM |
i want select some word open in the notepad | gsrikanth | Office | 3 | 02-25-2012 02:47 PM |
How make WORD 2007 act like Notepad | WASplawn | Word | 6 | 09-27-2011 10:17 AM |