Extracting and Modifying Field Code

J

Jayawanth

In an INCLUDEPICTURE field, I use embedded field for storing relative path
for my image files -
INCLUDEPICTURE \d "{FILENAME \p}\\..\\Images\\Chap 2\\Circulatory
System.jpg" \* MERGEFORMATINET

When we retrieve the Field.Code.Text in VBA, sometimes I am getting the
evaluated absolute path (i.e. c:\\...) and sometimes the relative path
({FILENAME...).

Q: How do we access the actual field code stored? Where ever there is an
absolute path I want to change it to relative path.
- Jayawanth
 
G

Graham Mayor

Frankly I don't see how that field construction would produce a valid path
under any circumstances. The filename and path of the current document added
to the start of the path of the image is destined not to work. It would
produce something like
"c:\\path\\documentname.doc \\.. \\Images\\Chap 2\\Circulatory System.jpg"
which doesn't work for me :(

What is it that you actually want in your document.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Jamieson

Perhaps something based on...

Sub getfieldtext()
Dim r As Word.Range
Dim nestedf As Word.Field
Set r = ActiveDocument.Fields(1).Code
If r.Fields.Count > 0 Then
For Each nestedf In r.Fields
nestedf.ShowCodes = False
Next
End If
Debug.Print r.Text
Set f = Nothing

End Sub


(Doesn't deal with multiple levels of nesting)

Peter Jamieson

http://tips.pjmsn.me.uk
 
J

Jayawanth

Peter,
Thanks for the hint about extra spaces. It worked.
My Normal paragraph style is justified and this was introducing extra spaces
randomly in the Field code. Once I changed this to Left Aligned the extra
spaces disappeared.

Mayor,
The issue I am dealing with is Linked Picture Files in word 2007. Since the
Link UI has major UI blocks you had suggested INCLUDEPICTURE Fields - VBA
code was supplied by you. I was trying to extend the code to use Relative
Paths for File portability.
Also whenever the INCLUDEPICTURE Field is moved it converts back to Linked
Picture. So I have written more macros to locate any links, Absolute Paths
and convert these to Fields and Relative paths.

Thanks both for all the help.
- Jayawanth
 
G

Graham Mayor

I might have known macropod would have been behind something like that ;)
Thanks for the link.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Jamieson

FWIW the original idea was mine (although doubtless others have had the
same notion at one time or another), but macropod's "extend and
summarise" is as always an easier read than the original thread.

Peter Jamieson

http://tips.pjmsn.me.uk
 
G

Graham Mayor

What can I say - foot in mouth come to mind :eek:(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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