How to copy date from excel to word

JJabra

New Member
Joined
Aug 19, 2019
Messages
37
Hi,

I have the below code which opens a word document and find words in column A and replaces it with the text in the adjacent cell in Column B. This works well.

My issue is that when it copies a date from one of the cells to word, it displays the date as a number rather than a date.

VBA Code:
Public Sub Wordfindandreplace()

Dim ws As Worksheet, msWord As Object, itm As Range

Set ws = ActiveSheet
Set msWord = CreateObject("Word.Application")

With msWord
.Visible = True
.Documents.Open ("\\Desktop\My Documents\Test Document.docx")
.Activate

With .ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting

For Each itm In ws.UsedRange.Columns("A").Cells

.Text = itm.Value2

.Replacement.Text = itm.Offset(, 1).Value2

.MatchCase = False
.MatchWholeWord = False

.Execute Replace:=2
Next
End With
SaveChanges = False
End With
End Sub

Any help would be appreciated.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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