Marcos

D

denmarfl

Running Word 2007; Vista Home Prem 32 Bit

Created a Marco that when the assigned keys are pressed it automatically
inserts my personal info at the top of my letter (Name\address\City\Stae\Zip)
and it also inserts the current date.

I included the date in the Macro so when I write a letter I didn't need to
type in the date under my personal info.

But what is happening is when I open the letter days later, instead of the
date the letter was created showing up under my Personal info, the Current
date appears. I of course would want the date the letter was typed to always
appear to document the date the letter was typed.

Can I still use the Marco to insert the date under my personal info, but,
when the letter is opened at a later date the Original date display. If so,
how would I do that?
 
S

Stefan Blom

You can use the following code to insert the current date (in the "Month
Day, Year" format) via a macro:

Selection.InsertAfter Format$(Now, "MMMM D, YYYY")

If you had posted the code you are using, it would be easier to "adjust" the
code to what you already have.
 
D

denmarfl

Below is a copy of the Macro.....

Address Macro
'
'
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:="Name"
Selection.TypeParagraph
Selection.TypeText Text:="Street"
Selection.TypeParagraph
Selection.TypeText Text:="City, Sate Zip"
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
True, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
Selection.TypeParagraph
End Sub
********************

I should EDIT the Macro, delete line 8 "Selection.InsertDateTime
DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _"

and replace it with your "Selection.InsertAfter Format$(Now, "MMMM D,
YYYY")" line

and doing this the Marco when used will insert the Date I am typing the
letter, and when I open that letter days later the original date the letter
was typed will be displayed?
 
G

Greg Maxey

Your specific problem is that you are inserting the date as a {DATE}
field which always shows the current system date.

If I wanted to pursue your approach, I would eliminate the field
altogether and adapt your code as follows:

Sub AddressMacro()
ActiveDocument.Range(0, 0).Select
With Selection
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeText "Name" & vbCr _
& "Street" & vbCr _
& "City, Sate Zip" & vbCr
.ParagraphFormat.SpaceAfter = 24
.TypeText Format(Date, "MMMM, d, yyyy") & vbCr
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.ParagraphFormat.SpaceAfter = 0
End With
End Sub

As for the generally adopted method of achieving what appears to be
your ultimate goal, I would concur with Ms. Barnhill's suggestion.

Still, rather than tell you bluntly what you should or shouldn't do, I
would rather try to answer your question, suggest the alternative, and
let you decide for yourself.

Good luck.
 
D

denmarfl

I'm a little new at yhis, are you advisng that if I deleted my entrie code
for this Marco, and copied your entire code, as typed by you, entering lines
and indents (in otherwords, copy and paste) into this Marco by using EDIT, I
will achieve my goal?
 
G

Greg Maxey

Well if are really determined to pursue a macro approach then yes. Copy
this code into a standard code module. See:
http://www.gmayor.com/installing_macro.htm

Sub AddressMacro()
ActiveDocument.Range(0, 0).Select
With Selection
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeText "Name" & vbCr _
& "Street" & vbCr _
& "City, Sate Zip" & vbCr
.ParagraphFormat.SpaceAfter = 24
.TypeText Format(Date, "MMMM, d, yyyy") & vbCr
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.ParagraphFormat.SpaceAfter = 0
End With
End Sub

My advise however is to look at the link that Ms. Barnhill provide you and
pursue a template solution.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 

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