Change the date format after copying from Excel workbook to Word file

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome. I have this code to create and copy data to a Word file and it works fine for me. Except for the date format in column C, it is copied as follows:
dd/mm/yyyy
What I'm looking for is how to change the date format after copying to yyyy/mm/dd
I tried changing it in the master data, but to no avail


VBA Code:
Sub ExcelToWordSheet1()
Dim lr As Long
Dim WS As Worksheet: Set WS = Sheets("Sheet1")

On Error Resume Next
Dim docDest As Word.Document
Dim src As Word.Application
Set src = CreateObject("word.application")
src.Visible = True

xname = "Word"

XPath = ThisWorkbook.path & "\" & xname
 
  Application.ScreenUpdating = False
 
 lr = WS.Cells(WS.Rows.Count, "A").End(xlUp).Row
 WS.Range("A7: k" & lr).Copy
      
Set docDest = src.Documents.Add
src.Selection.PasteExcelTable _
    LinkedToExcel:=False, WordFormatting:=False, RTF:=False
    Application.CutCopyMode = False
    
src.ActiveDocument. _
   PageSetup.Orientation = wdOrientLandscape
src.ActiveDocument. _
   PageSetup.PaperSize = WdPaperSize.wdPaperA3
 
    If Dir(XPath, vbDirectory) = "" Then MkDir XPath
          docDest.SaveAs XPath & "\" & WS.Name & ".docx"
          
              docDest.Close
            Set docDest = Nothing
       src.Quit
    Set src = Nothing
     Application.ScreenUpdating = True
    MsgBox "Done", vbInformation
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
in excel it is like this. Change it to the format you want. If it still doesn't change then change the locale of the software
VBA Code:
Sub Date_Format()
'
' Date_Format Macro
'

'
    Selection.NumberFormat = "dd-mm-yyyy"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,961
Members
452,539
Latest member
delvey

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