Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting filename into clipboard (2003 SP2)

    I use the following code to insert the full path and filename into a document (as a field):

    Sub InsertFullFilename()
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "FILENAME p ", PreserveFormatting:=True
    End Sub

    I use this both when I want to have the filename in a document, but also when I want to file a document I've received in the email, delete the document from the email message, and put the document's full name into the email, so that I can find it again easily.

    I'm increasingly receiving form documents <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15> which don't permit the macro to run; and in any case, it's silly to insert the field with the filename only to deleted it again to copy it into an email. There must be a better way to get the document's path and filename into the clipboard, for copying into the email.

    Can anybody help with the appropriate code? I think it's something.Copy - but I can't seem to get the right something (and I'm probably wrong).

    Many thanks in anticipation.

    Peter English.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting filename into clipboard (2003 SP2)

    You can use the DataObject for this. It requires a reference to the Microsoft Forms 2.0 Object Library; the easiest way to set this is to insert a userform in the Visual Basic Editor, then remove the userform again; the reference will remain set. The following macro will place the full name of the active document on the Windows clipboard:
    <code>
    Sub CopyFileName()
    ' Create data object
    Dim objData As New MSForms.DataObject
    ' Place full name in data object
    objData.SetText ActiveDocument.FullName
    ' Place it in the Windows clipboard
    objData.PutInClipboard
    Set objData = Nothing
    End Sub</code>

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting filename into clipboard (2003 SP2)

    How bizarre that you have to create a userform for this to work!

    But work it does. Thank you very much for your help.

    Peter.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting filename into clipboard (2003 SP2)

    Strictly speaking, you don't have to create a userform, only to set a reference to the Microsoft Forms 2.0 Object Library. You can do this in Tools | References..., but creating a userform is a convenient way to do so.

    The alternative would be to use Windows API functions to place the filename on the clipboard. Theoretically, this is more efficient, but it's also a lot more work.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Getting filename into clipboard (2003 SP2)

    This post over on the Outlook board might be of interest: <IMG SRC=http://www.wopr.com/w3timages/starpost.gif> Outlook Attachment Removal Manager (OL 2002 SP-2).

  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting filename into clipboard (2003 SP2)

    Wahay! I've wanted something like that for years and years and years <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

    Thank you!

    P.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •