Replace Text from Excel Sheet to Notepad

In this post we will show how to modify data in the Notepad from the Excel spreadsheet. We will write one macro here to do our job. I am sure you must have done manual copy-paste from excel to notepad many times. This macro will not only save your time but also make sure that there is no error that you could do manually.

There is an excel sheet with the two columns, Employee ID and Employee Name. We also have a notepad file which has only the Employee ID of the employee.

Our task is to replace the Employee Id in the notepad with their corresponding Employee Name. The Employee Name needs to be picked from the excel file.

Our Macro will one by one go through each of the Employee Id in the excel sheet and search it in the notepad file, if Employee Id is found in the notepad it will be replaced by the Employee Name which is present right next to the Employee Id

Backup of the Notepad file

As a safety measure a backup of the Notepad file is created and saved in a folder with the name Backup_ExcelSheetFileName. The Backup Notepad file will have Backup_ Prefixed to original name and each time the Macro is run the old Backup file will be over written.

How to use this Macro

1. Lets assume the name of your excel sheet is replace_text_notepad.xls and the name of your notepad file is replace_text_notepad.txt

2. The data in the Excel sheet and Notepad file is same as shown in the examples attached. Of course your data could be different.

NOTE: The important point to note here is that the Employee Id should be present in the first column starting from Cell A2 and the corresponding Employee Name should be present in second column starting from Cell B2.

3. Press ALT + F11 to open the Visual Basic Editor

4. Create a Module and copy-past the below code.

5. Again come back to the Excel sheet and press ALT + F8 and run the Macro Macro_Replace_From_Excel_To_Notepad

6. Enter the Notepad file name. In our case the name is replace_text_notepad.txt

Click OK to Run the Macro. The Notepad file should be present in the same folder where the excel sheet is located.

If you enter wrong File name here an error is thrown.

7. Now the task has been executed successfully and the Notepad File is also processed. You can open the Notepad and see the changes.

8. After the execution of the Macro you can see that a new folder named replace_text_notepad.xls (Folder name is same as the Excel Sheet name with .xls extension) has been created which has the backup of the original Notepad file with the name Backup_replace_text_notepad.txt

Sub Macro_Replace_From_Excel_To_Notepad()
 
Dim NotepadPath, NotepadFileName As String
 
''Take the Text file name from the user
NotepadFileName = InputBox("Enter the File Name of the Notepad file. File should be " & _
"present in the same folder (For example: FileName.txt)")
 
If NotepadFileName = vbNullString Then
    Exit Sub
End If
 
NotepadPath = ActiveWorkbook.path & "\" & NotepadFileName
 
' This for loop should only be called only if the Notepad file is found
If Not Len(Dir(NotepadPath)) = 0 Then
' Backup folder is created is not already created
Dim BackupPath As Variant
BackupPath = ActiveWorkbook.path & "\" & "Backup_" & ActiveWorkbook.Name
 
    If Not Len(Dir(BackupPath, vbDirectory)) = 0 Then
        'Do nothing
    Else
 
         MkDir (BackupPath)
    End If
 
' Text is file is copied to the Backup folder
FileCopy NotepadPath, BackupPath & "\" & "Backup_" & NotepadFileName
 
        'Open the Text file in Notepad
        value = Shell("C:\windows\system32\notepad.exe " & NotepadPath, vbNormalFocus)
        ' space after \notepad.exe_ and " is imp
        ActiveSheet.Select ' Select the Sheet
        Range("a2").Select
        For Each cell In Range(Selection, Selection.End(xlDown))
 
            value = OpenReplace(cell.value, cell.Offset(0, 1).value)
            ' Call OpenReplace function
        Next cell
 
        SendKeys "^s" 'CTRL + s (Save)
        SendKeys "%{F4}~" 'ALT + F4 (Close)
 
Else
MsgBox "File not found"
 
End If
Range("a2").Select
Range(Selection, Selection.End(xlDown)).Select
 
End Sub
 
 
 
Function OpenReplace(vText As Variant, vReplace As Variant)
' This function will open the notepad file and perform
' replace all function by sending keyboard actions
    SendKeys "^h" 'CTRL + H (Replace)
    SendKeys vText 'SHIFT + 2 (")
    SendKeys "{TAB}"
    SendKeys vReplace
    SendKeys "%a" 'ALT + A (Replace All)
    SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}" 'TAB x6 (to get to Cancel button)
    SendKeys "~" 'ENTER (press on Cancel button)
 
End Function

Have fun!

xxxxxxxxxxx

The first and the most important task is to get the Cabal Online hacks, As soon as you play this game, you will spend time thinking deeply Cabal Online l guild, how to get the Cabal Online quest, quickly and easily Cabal Online forums, Then sell it to get the Cabal Online cheats.

replica watch

rently the Vacheron Constantin Kalla Lune sale hottest selling handbags on Rado replica watches the tout. sign places Longines Heritage sale to bonanza tone imitations are www.goodbags.org, considering replica watches they mention select the Rado Ceramica Black Mens Watch R21347162 watch tops imitations further guarantee breitling replica watches your alleviation. This online watches replica Anya HindarMarch icon Handbags watches replica fare is recognized to watches replica copy exclusive of the boss when live comes to replicas handbags purchasing the chief type designer replica handbags imitations of the hot replica handbag agname name Anya HindarMarch handbags. No isolated commit replica tiffany jewelry surpassingly distinguish the discongruity chanel earrings (including you) when you replica tiffany jewelry occupancy an imitafake Designer Style Silver CZ Chain of Hearts Bracelet
fake Blue Topaz Sterling Silver CZ Cocktail Ring
Sterling Silver Classic Pink CZ Princess Cut Promise Ring outlet

GrandFantasia Gold

Gamers ought to know Grand Fantasia money if they really like to play this game. All gamers want to buy Grand Fantasia Gold to promote their character level easily, more Grand Fantasia Gold and GrandFantasia Gold they own, more items they can buy in game. While we provide you cheap Grand Fantasia Gold, surely you can get them at cheap prices.

Dungeon Fighter gold brings

Dungeon Fighter gold brings funny and happy time to players! Dungeon Fighter Online gold is very important for players. cheap Dungeon Fighter gold can make our character level up quickly. Players know it is hard to farm Dungeon Fighter money, so they would like buy Dungeon Fighter gold.

If you like using

If you like usingluminary gold to play which needs usebuy luminary gold, you can borrowcheap luminary gold from friends. You can buyluminary online gold,and than you useluminary money to continue the game

GrandFantasia Gold

You should know Grand Fantasia money if you play this game. I can say so: each gamer want to buy Grand Fantasia Gold to promote their character level easily, more Grand Fantasia Gold and GrandFantasia Gold they own, more items they can buy in game. While we provide you cheap Grand Fantasia Gold, surely you can get them at cheap prices.

ed hardy online

Exquisite design, superior material, exquisite craft. ed hardy online Close to her heart, the most perfect expression of your love.

Money gayweather loves

Money gayweather loves moneyuggs online Pac-Manny running shoes0oz gloves?
ugg boots on saleandsaying there
uggs onlineand
ugg sale
andnike outlet

reply

I think, standing in my personalugg boots for cheap view,

this article are very nice . In buy ugg bootsthis article,

I learned the knowledge that will good for myself. Thanks tougg bootsthe author of this article. Can read your article is

my lucky.

Dhonyobad...

Dhonyobad...

Very nice post! - useful to me in another project that I am doin

Good job!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
18 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

You may also like to read

Suggested Book to learn VBA