Selecting a Field

  • Thread starter Elizabeth A. Bañuelos
  • Start date
E

Elizabeth A. Bañuelos

I am creating a macro which inserts a Filename field into a document. I want
to then resize the font of ONLY the inserted field to 7pt. Presently my
macro reads as follows:

Selection.EndKey Unit:=wdStory
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
With Selection.Font
.Name = "Times New Roman"
.Size = 7
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1

This result was fine, as long as there was nothing else on the line ahead of
the Filename field insertion, which tends to USUALLY be the case. But,
because the macro indicates to return to the beginning of the line to apply
the font size, it also modifies any other text on the same line ahead of the
inserted field. I have tried various combinations of Shift, Ctrl and Alt
along with arrow keys for selecting the field with my keyboard while
recording the macro, but no luck.

So I need to modify the macro somehow so that it only selects the inserted
field instead of returning to the beginning of the line before it sizes the
font of the inserted field.

Any help would be greatly appreciated! Thanks!
 
H

Helmut Weber

Hi Elizabeth,

how about that one:#

Sub Test6009()
Selection.EndKey Unit:=wdStory
Selection.TypeText Text:=" " 'whatever
Selection.Font.Size = 7
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, _
Text:="FILENAME ", _
PreserveFormatting:=True
Selection.Font.Reset
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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