How to Replace Excel Cell Value in MS word by VBA....

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
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
Regards,
Krishna Kumar
9560305552
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,207,011
Messages
6,076,145
Members
446,187
Latest member
LMill

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top