Inserting the date into a table in word with VBA

L'Amore

Board Regular
Joined
Aug 21, 2013
Messages
116
I am struggling to work out how to fix this code. Its Word 2007 VBA
It errors because the cell of the table is selected in its entirety rather than its contents i think. Currently it's

Code:
With ActiveDocument.Tables(2)
    .Rows.Add BeforeRow:=ActiveDocument.Tables(2).Rows(2)
    .Rows(2).Range.Shading.BackgroundPatternColor = wdColorAutomatic
    .Rows(2).Range.Borders(wdBorderBottom).LineStyle = wdLineStyleDot
    .Cell(2, 2).Range.InsertDateTime "yy.MM.dd", False, wdEnglishUK, wdCalendarWestern, False
End With
This creates a new row under the the first one and formats it to look nice but errors when trying to enter the date. I have tried using the code in a keyboard enabled macro and it seems to work when I click in the cell but brings the same error when I highlight the whole cell (which lead me to suspect this was the problem)
Any ideas?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Thanks, but i was looking to make insert the date when a user iserts a enw row. So each new revision row has a date and a record of who created it.
Will bare this in mind for next time though.
Thnks!
 
Upvote 0
Thanks, but i was looking to make insert the date when a user iserts a enw row. So each new revision row has a date and a record of who created it.
But that isn't what your code does! Your code explicity inserts the date into cell B2, via:
.Cell(2, 2).Range.InsertDateTime "yy.MM.dd", False, wdEnglishUK, wdCalendarWestern, False

All I did was to show you a different way of doing the same thing.
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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