current week/date into Word 2000doc- how to?

B

breeze

I need automatically insert current date into specific Word docs(not for
all) with the following format: 'ww, dd-mm-yyyy', where 'ww' is current
week from the beginning of year(now is 30). MS Word 2000 have no such date
format in Insert > Date and Time >Available Formats.

Could someone help with right and convenient solution?(detail code and
description)
 
J

Jay Freedman

Hi breeze,

The line
Selection.InsertBefore Format(Now, "ww, dd-MM-yyyy")
will insert the string at the current cursor position. If you want it
somewhere else, you'll have to tell us what that location is.
 
J

Jezebel

This is the fourth time this question has been asked in the past week in
these forums. Is it an assignment question, or don't you like the responses
you've had so far?
 
B

breeze

Hello,

Some problem occurs when I tried implement your solution:

1)File > Properties > Custom
I do not see Type = string value in dropdown box. There are only Text, Date,
Number, Yes/No slection;

I dont see "DocDate" value of Property chosen in options(Error! No property
name supplied.)

2)About macros: where do macros should bw placed exactly? Could you show
exact code?

Is this code correct? It does not work.
Private Sub Document_New()

ActiveDocument.CustomDocumentProperties("DocDate") = format(Now,
"ww\/dd-mm-yyyy")
ActiveDocument.Fields.Update

End Sub

3)where the macro will be called from? From toolbar?

Please specify.

Best Regards,

breeze
----------------------------------------

Create a new template for these documents. Add a custom document property
(via File > Properties > Custom) called DocDate. Type = string. Give it a
dummy value like [DocDate].

At the location in your document where you want to see it, insert a field:
{ DocProperty DocDate }

Add an AutoNew macro containing:

ActiveDocument.CustomDocumentProperties("DocDate") = format(Now, "ww\/
dd-mm-yyyy")
ActiveDocument.Fields.Update


You'll need to modify the last line accordingly if the field is in a header
or footer rather than the body of the document.
 
B

breeze

Hi Jay,

Where this macros should be placed exactly - in ThisDocument >Document_New()
event ?


Private Sub Document_New()

Selection.InsertBefore Format(Now, "ww, dd-MM-yyyy")

End Sub

How to run macro from document toolbar?

Thanks
 
J

Jay Freedman

If you want this date to be placed at the beginning of every document
created from a particular template, then yes, put the Document_New macro in
the ThisDocument module of that template.

If instead you want the date to be placed wherever the cursor is when you
click a toolbar button, then you must name the macro something else (not one
of the special Document_ names, and not any of the Auto macro names like
AutoNew, and not the name of any built-in Word command) -- for example, name
it Public Sub WeekAndDate(). Also note that it must be Public, not Private,
and place it in a regular module created by clicking Insert > Module in the
VBA editor. After the macro is saved in the template, you can create the
button on a toolbar by using the procedure at
http://word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm.
 
B

breeze

1) Yes , I would like date to be placed wherever the cursor is when I click
a toolbar button.
Problem is that still can no write code myself, so I dont know what
components should be added to this line

Selection.InsertBefore Format(Now, "ww, dd-MM-yyyy")


I can insert code into Module and can create the button on a toolbar.


2) As to first way you mentioned (place data at the *beginning* of every
document created from a particular template) -this not work, I tried
already. Most definitely, this code is incomplete, something incorrect:


Private Sub Document_New()

Selection.InsertBefore Format(Now, "ww, dd-MM-yyyy")

End Sub

I was just wondering if anybody could mail me complete code, for both
solutions.

Thanks,
breeze
 

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