Changing Word Dates

C

Colonel Blip

I publish a weekly newsletter that has a date of publication at the first of
the newsletter. I have other sections in the newsletter that have different
dates that are respectively either 4 or 7 days later than the publication. I
would like to only have to change the 'master' date and have the rest change
to reflect it is one week later rather than manually changing these (which I
forget to do too often). Is there a way to do this in word without a macro?
If not, is there a way with vba code?
 
C

Colonel Blip

Thanks, found out about it this morning from another wopr member. It (or me)
was not quite up to the task. Here is my post there for those who might only
lurk here.

"Thanks. That was good stuff. Unfortunately either I don't understand some
of the subtleties or it doesn't quite have what I am after. Here is what I
want to do:

Date 1 <== I change this every week. When I do Dates 2 & 3 update
automatically
Date 2 = Date 1+4 days
Date 3 = Date 1+7 days

I tried to simply install the field codes for calculating a stepped date,
but had problems when trying to get it to do what I wanted. Also, I always
have to remember to update fields so it is just as easy for me to forget
that as to forget changing the 2 dates. <g> :-(

In any event, on changing the stepped date code I tried to change the line
suggested to reflect the next Wednesday and Sunday after the date in Date 1.
I could do the Wed. without any problem. However, changing the Sunday date
worked fine until I changed my computer calendar date to reflect next Sunday
or any days following. Suddenly the date produced jumped to August!
Obviously I missed something in what I was doing."

 
C

Charles Kenyon

Word date field calculations are complex, as you've discovered.

Consider using a createdate field or an ASK field to get your first date. A
CreateDate field has a number of advantages because it is automatic and you
can put it directly into your calculation fields. A disadvantage is that you
may have to reset your computer's date before creating your documents to get
the proper dates in your document.

Put your date fields in a template so that when you create a document based
on the template they are all set.

Ctrl-A, F9 updates all the fields in the body of your document. Unless you
have other fields you don't want updated this works pretty well. It can be
automated with macros if you need to do so.

People won't be able to give much constructive help, other than the
reference you've already received, unless you actually post your field
contents here so that the fields themselves can be examined.

An alternative that is perhaps harder for you (but is easier to give
assistance with) would be to set up a UserForm that asks for your first date
and inserts the dates you want at the appropriate places. (VBA code is a lot
easier to debug than are date calculation fields.) Look at the MVP FAQ site
for help on UserForms.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Colonel Blip

Charles,

I went straight to the bottom and followed the userform approach (practice)
according to the MVP FAQ. I can see how I can get the Date 1 to change;
however, if I want Date 2 and 3 to change there must be some code I must
enter to change them automatically. In other words, to make a userform with
entries for all three dates defeats the purpose. I can do that manually
(hope this is clear).

Date 1 <== I change this every week. When I do Dates 2 & 3 update
automatically
Date 2 = Date 1+4 days
Date 3 = Date 1+7 days

Also, my process is to use the newsletter from last week as a basis for the
newsletter for this week. I simply replace some, but not all, of the
content. I suppose I could make a template off of it - haven't tried that -
but to do so means I will be starting with a document that each week will be
a week older than last week's. This is a bit of a hassle since in this
newsletter I have some list from which I simply drop the first line and add
a new line. Starting with a template would mean replacing all of the list
content after a while.

So, having said that I can see (I think) how to use a userform on last
week's document to make Date 1 change to this week, but need to be able to
make the others change automatically.

Regarding the need to post my fields I was using I will do that in another
reply to keep from getting to messy here.

Thanks.

 
C

Charles Kenyon

You makes your choices ... and then lives with 'em.

If you are going with a constantly revised document you are somewhat more
prone to corruption so keep backups.

See the vba pages on the MVP FAQ site about inserting text at bookmarks. The
suckers tend to disappear on you!

Look up the DateAdd function in vba help. You get the first date through
user input and then use DateAdd to create your other two dates.

I would recommend adding a custom toolbar with a button to show your
userform to your document.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Colonel Blip

See comments

Charles Kenyon said:



Well, I planned to copy and paste the code here but all that shows up is the
result of the field calc. Is there a way to show it short of a screen print
(which I believe is frowned on here)?


 
C

Charles Kenyon

Since you are going with a userform there is little point in copying the
fields. Mostly they have to be retyped by hand. I believe one of the MVPs
came up with a utility that would translate field codes to plain text but I
don't know who or how.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

Suzanne S. Barnhill

If you have the field code displayed and carefully select just the code
itself (omitting the outside braces), you can paste it, but when you have
nested fields, this can be pretty tedious.
 
M

macropod

Hi Charles,

Give the following a try:
Sub FieldCodeToString()
Dim Fieldstring As String, NewString As String, CurrChar As String
Dim CurrSetting As Boolean, fcDisplay As Object
Dim MyData As DataObject, X As Integer
NewString = ""
Set fcDisplay = ActiveWindow.View
Application.ScreenUpdating = False
CurrSetting = fcDisplay.ShowFieldCodes
If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
Fieldstring = Selection.Text
For X = 1 To Len(Fieldstring)
CurrChar = Mid(Fieldstring, X, 1)
Select Case CurrChar
Case Chr(19)
CurrChar = "{"
Case Chr(21)
CurrChar = "}"
Case Else
End Select
NewString = NewString + CurrChar
Next X
Set MyData = New DataObject
MyData.SetText NewString
MyData.PutInClipboard
fcDisplay.ShowFieldCodes = CurrSetting
End Sub

The text version of the field is copied to the clipboard, from where you can
paste it into whatever.

Cheers
 
C

Charles Kenyon

Hi,

Thank you. Seems to work very well. What followsi is my implemented version
which includes a message box at the end to remind me that I have to paste it
somewhere. This is handing enough that it is going on my Fields toolbar.

Sub FieldCodeToString()
' Posted to the xx newsgroup on 15 April 2004 by macropod
' Converts a Word field code to a string (in the clipboard)
'
Dim Fieldstring As String, NewString As String, CurrChar As String
Dim CurrSetting As Boolean, fcDisplay As Object
Dim MyData As DataObject, X As Integer
NewString = ""
Set fcDisplay = ActiveWindow.View
Application.ScreenUpdating = False
CurrSetting = fcDisplay.ShowFieldCodes
If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
Fieldstring = Selection.Text
For X = 1 To Len(Fieldstring)
CurrChar = Mid(Fieldstring, X, 1)
Select Case CurrChar
Case Chr(19)
CurrChar = "{"
Case Chr(21)
CurrChar = "}"
Case Else
End Select
NewString = NewString + CurrChar
Next X
Set MyData = New DataObject
MyData.SetText NewString
MyData.PutInClipboard
fcDisplay.ShowFieldCodes = CurrSetting
MsgBox NewString & " is now in the Clipboard for pasting."
End
--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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