Capturing the name of a Word file while working with the file

  • Thread starter Thread starter Opinicus
  • Start date Start date
O

Opinicus

Is there a way to capture the name of a Word document that I'm working with
while the file is open and I'm in the file? By sending it to the clipboard,
for example?
 
Is there a way to capture the name of a Word document that I'm working with
while the file is open and I'm in the file? By sending it to the clipboard,
for example?

The following macro might do the trick:

' === Begin of macro ===
Sub FileName()
Dim obj As DataObject

Set obj = New DataObject

obj.SetText ActiveDocument.Path & ActiveDocument.Name
obj.PutInClipboard
End Sub
' === End of macro ===

Yves
 
Capture it for what purpose? In order to best answer your question, we need
to know what you want to do with the name that you have 'captured'.


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
You can insert a FILENAME field in the document, if that's what you mean.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
The following macro might do the trick:

' === Begin of macro ===
Sub FileName()
Dim obj As DataObject

Set obj = New DataObject

obj.SetText ActiveDocument.Path & ActiveDocument.Name
obj.PutInClipboard
End Sub
' === End of macro ===

Thanks, Yves. This looks like it should do what I want but it chokes on the
first line (Dim obj) with a "User-defined type not identified" error. What
am I doing wrong?
 

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

Back
Top