Paste date / time via macro from Excel into Word

adamprocter

Board Regular
Joined
Apr 13, 2015
Messages
53
I am creating a word document from excel which is working great bar these 2 fields they are set in excel as Date and Time columns, which are originally generated from NOW() & TODAY()
The date seems to paste in almost ok (DD/MM) aka 11/06 but misses of the year and the time seems to paste in the sum or the unix date and not something understandable.
Am assuming I need to not copy the value but the adjusted text


Code:
  Set wdRng = wdDoc.Bookmarks("myDate").Range
    wdRng.Text = Sheets("my sheet 1").Range("Q65536").End(xlUp).Value
  
  Set wdRng = wdDoc.Bookmarks("myTime").Range
      wdRng.Text = Sheets("my sheet 1").Range("P65536").End(xlUp).Value

any help much appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try...

Code:
  Set wdRng = wdDoc.Bookmarks("myDate").Range
    wdRng.Text = Format(Sheets("my sheet 1").Range("Q65536").End(xlUp).Value, "dd/mm/yyyy")
  
  Set wdRng = wdDoc.Bookmarks("myTime").Range
      wdRng.Text = Format(Sheets("my sheet 1").Range("P65536").End(xlUp).Value, "h:mm AM/PM")

Change the formats as desired.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,203,076
Messages
6,053,396
Members
444,661
Latest member
liamoohay

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