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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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