Macro question

T

TBoe

I have about 50 Word documents that I have to change 4 date fields to
SaveDate format. I wanted to record a macro to delete the date, create a
text box, and
install the SaveDate field. Not being too familiar with macros, can this be
accomplished? I tried to record the macro but it won't let me delete text or
create a new line. The doc is not protected. Am I missing something? The
mouse cursor has the tape icon on it but I really cannot do any editing. Is
this nomal?

TY
 
C

Charles Kenyon

Why the text box? Generally fields in text boxes are not a good idea, and it
makes the programming a lot more tricky.

To get you started on handling a bunch of files, you might want to look at
http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm which is on doing a replace
on all files in a directory.

In your case it would be relatively simple to adapt this to replace all DATE
codes with SAVEDATE codes, which may not be what you want.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

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




--------- --------- --------- --------- --------- ---------
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.
 
T

TBoe

Thanks for the info Charles. The reason for the text box was for formating
issues.
I guess I really don't need them. Next to the date is a sentence and I
thought
it would be easier if you had to enter a date then the test would not move.
 
C

Charles Kenyon

A table would do the same thing. The thing about text boxes is that they are
not in the same "layer" of the document as your regular text. It adds a big
level of complexity. If you want something in a margin, you could put it in
a frame (which acts a lot like a text box, but is still in the text layer).

The following code creates a frame with a SaveDate field for the left
margin.

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 4/13/2006 by Charles Kyle Kenyon
'
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"SAVEDATE \@ ""d-MMM-yy"" ", PreserveFormatting:=False
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
ActiveDocument.Frames.Add Range:=Selection.Range
With .Frames(1)
.Select
.TextWrap = True
.WidthRule = wdFrameExact
.Width = InchesToPoints(0.8)
.HeightRule = wdFrameAuto
.HorizontalPosition = wdFrameLeft
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.VerticalPosition = InchesToPoints(0)
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.HorizontalDistanceFromText = InchesToPoints(0.1)
.VerticalDistanceFromText = InchesToPoints(0)
.LockAnchor = False
End With
.Collapse
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeText Text:="Saved"
.TypeParagraph
End With
End Sub

It is very sloppy, based on recording. Run it to get a frame. Adjust the
formatting of the frame and the field until they are to your liking. Save
this as an AutoText entry.

Then, write your code to find date fields and in place of the date field
insert the Autotext entry, which will be the framed SaveDate field.

Hope this helps. I'm sure there is a more elegant way.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

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




--------- --------- --------- --------- --------- ---------
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