finding the week number in word

S

spalatty

I can't figure out how to find the week number if a date is entered in
Microsoft Word 2003. For example 1/1/2006 would be week 1. Excel has this
feature(Weeknum) but I need to use it in word. Can anyone help me with this?
 
J

Jay Freedman

I can't figure out how to find the week number if a date is entered in
Microsoft Word 2003. For example 1/1/2006 would be week 1. Excel has this
feature(Weeknum) but I need to use it in word. Can anyone help me with this?

Use the Format function, using the ww format string as shown in the
VBA help topic "User-Defined Date/Time Formats (Format Function)".
Here's a little sample code:

MsgBox "Today is " & _
Format(Now, "dddd dd mmmm") & _
", in week " & _
Format(Now, "ww") & _
" of " & Format(Now, "yyyy")

If you need it as an integer instead of a string, you can use the CLng
function:

Dim wk As Long
wk = CLng(Format(Now, "ww"))

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
C

Carim

Hi,

Adapted from Macropod and Chip Pearson,
http://www.cpearson.com/excel/weeknum.htm
you could without VBA insert a field code :
{QUOTE
"{DATE \@ "d MMMM yyyy"} is Week "
{SET yd{={DATE \@ d}+INT(({DATE \@ M}-0.986)*30.575)-
IF({DATE \@ M}>2,2-(MOD({DATE \@ yy},4)=0)-
(MOD({DATE \@ yyyy},400)=0)-6+(MOD({DATE \@ yy},100)=0),0)}}
{=yd/7 \# 0}
.."}

This field code will show both current date and week number.

HTH
Cheers
Carim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top