+ Reply to Thread
Results 1 to 3 of 3

Pasting embedded OLE objects to specific filename

  1. #1
    atvaluesoftware@gmail.com
    Guest

    Pasting embedded OLE objects to specific filename

    The following code copies an embedded OLE object and pastes it to the
    specified path:

    Sub Test()
    ActiveSheet.OLEObjects("Object 1").Copy

    'paste to activeworkbook's path
    CreateObject("Shell.Application") _
    .Namespace(ActiveWorkbook.Path) _
    .Self.InvokeVerb "Paste"
    End Sub

    What about pasting the object and giving it a particular filename
    during the paste action? With the code given, the object is pasted
    correctly. However, by default, the filename used in the pasting is the
    filename that was specified during the Insert > Object > Create from
    File process (initial insert of the object).

    Is there anyway to change the filename used in the paste?


  2. #2
    Tim Williams
    Guest

    Re: Pasting embedded OLE objects to specific filename

    Run a Dir() on the folder first, then check which is the new file
    following the paste, then rename it....

    Tim.


    <atvaluesoftware@gmail.com> wrote in message
    news:1121355057.125109.289240@g44g2000cwa.googlegroups.com...
    > The following code copies an embedded OLE object and pastes it to
    > the
    > specified path:
    >
    > Sub Test()
    > ActiveSheet.OLEObjects("Object 1").Copy
    >
    > 'paste to activeworkbook's path
    > CreateObject("Shell.Application") _
    > .Namespace(ActiveWorkbook.Path) _
    > .Self.InvokeVerb "Paste"
    > End Sub
    >
    > What about pasting the object and giving it a particular filename
    > during the paste action? With the code given, the object is pasted
    > correctly. However, by default, the filename used in the pasting is
    > the
    > filename that was specified during the Insert > Object > Create from
    > File process (initial insert of the object).
    >
    > Is there anyway to change the filename used in the paste?
    >




  3. #3
    okaizawa
    Guest

    Re: Pasting embedded OLE objects to specific filename

    I don't know how to name the file while pasting.
    but after pasted, it can be renamed. for example,

    Sub test2()
    Dim FileName As String
    Dim TempPath As String
    Dim TempFile As String

    On Error GoTo ErrorHandler

    If ActiveWorkbook.Path = "" Then Exit Sub
    FileName = ActiveWorkbook.Path & "\My.mdb"
    TempPath = ActiveWorkbook.Path & "\TMP"

    If Dir(FileName) <> "" Then
    MsgBox "'" & FileName & "' already exists."
    Exit Sub
    End If

    If Dir(TempPath, vbDirectory) = "" Then MkDir TempPath

    If Dir(TempPath & "\") <> "" Then
    MsgBox "Remove all files in '" & TempPath & "', then try again."
    Exit Sub
    End If

    'copy an oleobject
    ActiveSheet.OLEObjects("Object 1").Copy

    'paste to a temp-folder
    CreateObject("Shell.Application") _
    .NameSpace(CVar(TempPath)).Self.InvokeVerb "Paste"

    'get the filename
    TempFile = Dir(TempPath & "\")
    If TempFile = "" Then
    MsgBox "No file."
    Exit Sub
    End If

    'move and rename the file
    Name TempPath & "\" & TempFile As FileName

    'TempPath seems to be locked while procedures are running.
    'the below might not be able to remove it.
    On Error Resume Next
    Kill TempPath & "\*"
    RmDir TempPath

    Exit Sub

    ErrorHandler:
    MsgBox Err.Description, vbExclamation
    Exit Sub

    End Sub

    --
    HTH

    okaizawa


    atvaluesoftware@gmail.com wrote:
    > The following code copies an embedded OLE object and pastes it to the
    > specified path:
    >
    > Sub Test()
    > ActiveSheet.OLEObjects("Object 1").Copy
    >
    > 'paste to activeworkbook's path
    > CreateObject("Shell.Application") _
    > .Namespace(ActiveWorkbook.Path) _
    > .Self.InvokeVerb "Paste"
    > End Sub
    >
    > What about pasting the object and giving it a particular filename
    > during the paste action? With the code given, the object is pasted
    > correctly. However, by default, the filename used in the pasting is the
    > filename that was specified during the Insert > Object > Create from
    > File process (initial insert of the object).
    >
    > Is there anyway to change the filename used in the paste?
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1