Home » Questions » Computers [ Ask a new question ]

Is there a Word field code for the folder path?

Is there a Word field code for the folder path?

In MS Word you can insert a field code to show the document file name with the option to include or not the full path.

Asked by: Guest | Views: 53
Total answers/comments: 1
Guest [Entry]

"I'm still playing around with this as it seems like a reasonable enough thing to expect to be able to do... but so far the only way I've found is by the rather nasty cheat of insering a filename field with path and then applying a white font colour to the text (i.e. the filename itself) and so you end up with just the path and a block of invisible text after it.

Problem is that this could mess with formatting and is really badly kludgy.


Slightly less kludgy solution...

If you don't mind having a macro in your normal.dotm and having a hidden variable in your document then you may be able to use this macro and set a button on your quick access to run it... I've tried it and it works on a macro free document so the document itself does not need macros to use this method, I'd put this in my normal.dotm template...

Sub updatePath()
' updatePath Macro
Dim myPath As String
myPath = ActiveDocument.Path
If myPath = """" Then
'do nothing as the document has no path... needs to be saved first
If ActiveDocument.Variables.Count = 0 Then
ActiveDocument.Variables.Add Name:=""myPath"", Value:=myPath
i = 1
Do While i < (ActiveDocument.Variables.Count + 1)
If ActiveDocument.Variables.Item(i).Name = ""myPath"" Then
ActiveDocument.Variables.Item(i).Value = myPath
End If
i = i + 1
End If
End If

End Sub

And then just add a field code


which when updated after running the macro above would do exactly what you wanted. Granted it is two or three clicks rather than just a simple update, but it does mean that your exported document gets the proper field type and only people with this macro get to say where the document should be stored :)"