Get source file name

A

Anders F

How can I get the document file name? I want to set it in the header but I
can not do it. This is as far as I get (see below), when I try I get the
message
"The index into the specified collection is out of bounds." I suppose it is
Shapes that is the culprit, if I set Shapes(0) I get the same message.

I have used Word for some time but never for anything like this. According
to
Help, the source name does refere to a linked OLE object but I only have
one document, is it possible to declare it as an OLE object? Or is there
some other way to get the source file name?

Thanks for any answer

Sub MyInitDocument()

ActiveDocument.Sections(1).Headers(1).Range.Text = _
ActiveDocument.Shapes(1).LinkFormat.SourceName

End Sub
 
J

Jonathan West

Hi Anders

The Document filename is returned by the ActiveDocument.Name property (or
FullName property if you want to the include the full pathname)

But if you just want to include the filename in the header, you don't need
any VBA at all;. Just include a FILENAME field in the header. if you want
the full pathname, include the \p switch in the field.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Anders,

could it be, that your object isn't a shape at all,
but an inlineshape?

MsgBox ActiveDocument.InlineShapes(1).LinkFormat.SourceName

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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