Share via

Word - field codes

Anonymous
2019-07-18T19:09:57+00:00

Hi Guys

I would like to put the document file name in the footer of a Word doc, but without the file extension.  If this can be achieved by editing the field code can anyone tell me what the field code needs to be?  Thanks.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2019-07-18T22:23:52+00:00

In the footer, insert the following field

{ DOCVARIABLE filename }

and then run a macro containing the following code

Dim i As Long, j As Long

With ActiveDocument

    .Variables("filename") = Left(.Name, InStr(.Name, ".") - 1)

    For i = 1 To .Sections.Count

        With .Sections(i)

            For j = 1 To .Footers.Count

                .Footers(j).Range.Fields.Update

            Next j

        End With

    Next i

End With

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-07-20T06:51:21+00:00

    Hi Doug

    Since my short reply yesterday, I have created a footer that I routinely use as a 'building block' and together with your macro, saved in the Normal template, now makes creating the whole footer much easier/quicker. so thanks again.

    {PeteB}

    ,

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-07-19T18:05:25+00:00

    Thanks heaps - spot on.

    {PeteB}

    Was this answer helpful?

    0 comments No comments