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.
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
983
Office Version
2007
Platform
Windows
Hi there. Try using .Text rather than .Value2
 

Watch MrExcel Video

Forum statistics

Threads
1,102,775
Messages
5,488,776
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top