How to get name of the file from the dialogue "Links"?

A

avkokin

Hello.
The document has one picture (for example). It was inserted from file
by command "Insert and Link". If we will select this picture and open
the dialogue "Links" then we will see link to this picture (path to
it). My question: how to get name of the file for this picture (only
name, exclude of the path)? Thank you.
Sincerely, Anton Kokin
 
G

Graham Mayor

The Insert and Link function inserts an IncludePicture field, so it is
possible to read the code associated with the IncludePicture field and
extract the filename from that code eg

Dim iFld As Integer
Dim sName As String
Dim sStart As String
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldIncludePicture Then
sName = .Code
sName = Replace(sName, Chr(34) & " \* MERGEFORMAT ", "")
sStart = InStrRev(sName, "\")
sName = Right(sName, Len(sName) - sStart)
MsgBox sName
End If
End With
Next iFld


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

avkokin

The Insert and Link function inserts an IncludePicture field, so it is
possible to read the code associated with the IncludePicture field and
extract the filename from that code eg

Dim iFld As Integer
Dim sName As String
Dim sStart As String
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldIncludePicture Then
sName = .Code
sName = Replace(sName, Chr(34) & " \* MERGEFORMAT ", "")
sStart = InStrRev(sName, "\")
sName = Right(sName, Len(sName) - sStart)
MsgBox sName
End If
End With
Next iFld

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hello Graham. Thank you very much. I think what into the string
"sStart = InStrRev(sName, "\")" should change the slash "\" to "/".
Then all ok.
 
G

Graham Mayor

Hello Graham. Thank you very much. I think what into the string
"sStart = InStrRev(sName, "\")" should change the slash "\" to "/".
Then all ok.

It was correct as written. The IncludeText field inserts the following:

{ INCLUDEPICTURE "D:\\My Documents\\My Pictures\\Filename.jpg" \*
MERGEFORMAT }

InstrRev is searching for the '\' before Filename.

However it is possible to express the field as

{ INCLUDEPICTURE "D:/My Documents/My Pictures/Filename.jpg" \* MERGEFORMAT }

but this does not occur with the Insert Picture and Link command. If that
construction is what you have, then the change would be necessary.


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

avkokin

It was correct as written. The IncludeText field inserts the following:

{ INCLUDEPICTURE "D:\\My Documents\\My Pictures\\Filename.jpg" \*
MERGEFORMAT }

InstrRev is searching for the '\' before Filename.

However it is possible to express the field as

{ INCLUDEPICTURE "D:/My Documents/My Pictures/Filename.jpg" \* MERGEFORMAT}

but this does not occur with the Insert Picture and Link command. If that
construction is what you have, then the change would be necessary.

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Yes, Graham, the second case just my very case, with the reverse
slash. Thank you very much for your help.
 

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