krishnaoptif
Board Regular
- Joined
- Sep 17, 2010
- Messages
- 140
Hi Experts,
I want to replace excel cell value in ms word file.... if Excel Column A value is present in ms word document then replace word doc value with Excel Column B with sort name of Column A
As.. range A3 = Visual Basic and column B3 = VBA then will replace in ms word doc all "Visual Basic" keyword with "VBA" keyword with background yellow color in ms word..
if same word like "Visual Basic" is many times in ms word then all words replace with "VBA" word with yellow color but the first number of replaced word will be in read color back ground color in ms word file.....
Please find below code macro which i have developed till ms word file picker...
Excel Column A Excel Column B
<colgroup><col><col></colgroup><tbody>
</tbody>
Regards,
Krishna Kumar
9560305552
I want to replace excel cell value in ms word file.... if Excel Column A value is present in ms word document then replace word doc value with Excel Column B with sort name of Column A
As.. range A3 = Visual Basic and column B3 = VBA then will replace in ms word doc all "Visual Basic" keyword with "VBA" keyword with background yellow color in ms word..
if same word like "Visual Basic" is many times in ms word then all words replace with "VBA" word with yellow color but the first number of replaced word will be in read color back ground color in ms word file.....
Please find below code macro which i have developed till ms word file picker...
Excel Column A Excel Column B
Search Name | Replaced By |
Visual Basic | VBA |
Powerpoint | PPT |
<colgroup><col><col></colgroup><tbody>
</tbody>
Code:
Sub ReplaceExcelCellvalueInMswordFile()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
'File picker
Dim dlg As Variant
Dim dataPath As Variant
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
dlg.Title = "Select Excel Spreadsheet to import"
dlg.AllowMultiSelect = False
If dlg.Show = -1 Then
dataPath = dlg.SelectedItems(1)
'Me!browseDataPath.Value = dataPath
End If
Set wdDoc = wdApp.Documents.Open(dataPath)
wdApp.Visible = True
End Sub
Krishna Kumar
9560305552