Copy & paste embeded object to file system

Cross-post at:
http://stackoverflow.com/questions/27685791/copy-paste-embeded-object-to-file-system
Background:
I wrote a large piece of VBA code in an Excel workbook to help handle a lot of repeating jobs. I found it is painful to maintain and modify the code by using the "pool" VBA Editor. Then, I decided to move those VBA code to C# solutions, which I
suppose I can benefit from the modern editor - Visual Studio.
Problem:
Although I don't know too much about VBA, I know even less about C#. Hence I got some problem when I try to "translate" my VBA code to C#, and here is one of them:
I create a document-level solution for Excel. I need to embed some files (.cab, .exe) into the solution, so when I run a method (e.g. by clicking a button), those files will be copied to the file system, and do some job.
In VBA, I embedded those files in the Excel workbook, then I can copy the embedded objects to the clipboard by using the following VBA code:
Sheet1.OLEObjects("obj_cab").COpy
And then I can paste the object to the file system by using the following VBA code:
CreateObject("Shell.Application").Namespace("C:\Sample\").Self.InvokeVerb "Paste"
In the C# solution, I can use the following equivalent method to copy the embedded object to the clipboard:
Microsoft.Office.Interop.Excel.OLEObject OLEobj = (Microsoft.Office.Interop.Excel.OLEObject)sheet1.OLEObjects("obj_cab");
OLEobj.Copy();
Then I stuck here, I don't know how to get this object from clipboard and put it to the file system. The 'CreateObject' method does not exist in C#.
Anyone can help? Either a better way to embed those files or a working way to paste those objects (files) from clipboard to the file system?
Thanks a lot!

Hi FantaC,
It's possible to save the oleobject to the disk. But it's not very simple. Because when you call the Copy method of OLEObject to clipboard, it's actually not the exact the oleobject file itself, it's actually a wrapper of the file, it means that it has different
file headers and some other information from the original oleobject file.
To save oleobject on the disk, you need to analyze the byte array by yourself, this would be a little complicated. You could check the answer in this thread for the code sample:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/1ab7a178-8021-4c67-a14b-5031a254fd9c/saving-oleobject-content-to-a-file
The original poster of this thread also write a blogpost about this, you can check it here:
Saving OLEObject Content To File
Detailed information and code samples are provided in this blogpost.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • How can i copy,paste an Object ?

    How can i copy,paste an Object which i define by myself?

    implements Cloneable and define a clone method, for example
    public class ObjectA  implements Cloneable {
       // Data member
       String data;
       public ObjectA() {
       public void setData(String data) {
          this.data = data;
       public Object clone() {
           ObjectA tempObject = new ObjectA();
           tempObject.setData(this.data);
           return tempObject;
    }

  • Error in importing SLD objects via file system

    Hi
    I am transporting XI Sld objects e.g. products, software components, technical, business systems from dev to cons. I have cms in place but i need to prepare SLD objects before transporting ID objects. My dev is on SP 15 and Cons on SP 10..While transporting SLD product using file system i got following error:
    The target namespace for the special import already contains data for one or more export lines. Continuing this import may corrupt the state of your data.
    I have tried importing SLD objects between two SLDs of SP10 also..but same error came
    Plz..help
    thnx in advance!!
    Abhijeet Jangam

    Hi,
    <i>My dev is on SP 15 and Cons on SP 10..While transporting SLD product using file system i got following error:
    </i>
    See SAP Note 832142 for known restrictions about transporting objects between
    different XI 3.0 support packages And See SAP Note 834507 for known restrictions about cross-release transports.
    Also see the CMS Guide at market place, how to guide,
    https://websmp201.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700003090422005E
    Also refer 780297 for continiuosly updated errors.
    May be all this will help you to analyse if not directly arrive at the solution.
    All the best,
    Anirban.

  • Copy/paste issues with certain files...

        I notice that in some pdf files I get that I can't do a copy/paste.... I think the reason is because its a graphic vs real text (even though it is text that I see) not sure if I have the right terminology here....
    In any case I can't c/p....
    Also, when I do a word search that doesn't work, I assume it's for the same reason....
    Any work around for this, or a way to convert the file to pdf text ?

    Not with Reader no.
    Adobe Actobat has an OCR function or there are a few other third party applications that are dedicated OCR tools.
    cowboy1611 wrote:
    Right, I'm sure it's a graphic/image, so there is no tool to convert to text ?

  • Copy, paste typing object

    Is there any way to copy a "typing" object and paste it
    somewhere else? I'm trying to edit a project and one of my slides
    contains a typing object of a key being pressed. This object
    appears in the timeline but there does not seem to be any way to
    copy it and add it to a different slide. Any advice on how to do
    that?

    Hi gobaldsoon (I'm bald all the time!)
    Unfortunately there is simply no way to edit the typing
    object. Because of this, I find them way too limiting and never use
    them. What you
    can do, however, is to download fellow Adobe Community
    Expert Paul Dewhurst's Typing Text animation from the Captivate
    Exchange. You may visit the Captivate Exchange by
    Clicking
    Here
    Cheers... Rick

  • Copy/Paste between guest and host system

    I'm looking for the way to use the clipboard so that I can copy from host system to guest system.
    Is that possible?
    Thanks,
    Olivier.

    user7631797 wrote:
    Woow Pascal it seems to be a quite complicated task!
    I tried to install dkms with yum install dkms but it failed.
    And
    obotineau@VAIO-Ubuntu-GNOME:~$ /etc/init.d/vboxadd setup
    bash: /etc/init.d/vboxadd: No such file or directory
    So I miss two things, How to follow the Chapter 4 Guest Additions with these problems?
    Thanks,
    Olivier.
    Unfortunately, the VBOx docs can be pretty spotty.
    What is your guest OS?
    What is your host OS?
    From you example above it appears you are working with Ubuntu on one side or the other, but it it is not clear if that is host or guest.  If we can get that clarified perhaps we can offer some more assistance.

  • Is there a way to print (or copy/paste) a list of files I have in a folder?

    I have 42 pics in a folder, each with it's own file name. Is there any way I can print the list of files in the folder to be able to send just the file names via email?
    (I just want to let someone know what I have, not actually send them the phyical file)
    Thanks!

    Select them all, choose Copy from the Edit menu, paste into a location which only allows plain text, copy that text, and put it into the email.
    (52171)

  • Error while transporting objects using FIle system

    Hi All,
    I am getting the following error when I try to transport Repository or Directory objects from Development to quality.
    Internal error during pvc call: No space left on device.....
    But when I checked there is ample of space on the disk. Can anyone help me in resolving this issue.
    Also I am trying to set up CMS for PI7.0. Can someone please mail some good document or suitable links which can guide me for setting up the same.
    mail id [email protected]
    Regards
    Vinay

    Hi
    just to add
    Note :859465  addresses a different problem which is as follows. So I think it wont help here.
    Certain operations fail in DTR or in XI with a NullPointerException.
    regards
    krishna

  • Copy paste anchored objects in a table

    Hi all!
    I must design very often posters with a lot of brands logos  (events sponsors) distribuited like anchored objects in the cells of a table.
    Very frecuently, the list of brands changes after designed the poster, adding or deleting someones, and then i must replace the logos one by one.
    I'm programming a script that moves the content of the cells, making space to the new inserts, or filling the space leaved by brands out. I use the "content" property of the object "cell", and it really works with text (its useful for me in others cases, anyway) but it makes absolutly nothing with the anchored objects.
    Somebody have any idea that can help me?
    Thanks for your help, and sorry for my english!
    Jose

    Oh, and what is very helpful:
    The parent of an anchored object is a Character Object.
    Example 1:
    A text frame with an anchored object (the magenta square).
    The text frame is selected.
    If you ask for the count of characters in the text frame:
    app.selection[0].characters.length;
    The answer is "5"!
    The anchor, that is indeed the anchored rectangle, is treated as a character.
    If you select the anchored object and ask for its parent:
    app.selection[0].parent;
    The answer is "[object Character]".
    To move such an anchored object without loosing its anchordness, you have to move the character.
    In the above case, the character is characters[0] of the text frame. Or more precise, the characters[0] of texts[0] (all formatted text in the text frame) of the text frame. You also could go a step backward and say: in this case it's the characters[0] of texts[0] of the parentStory of the text frame
    To move it somewhere else (e.g. to a cell of a table), you must move it to another Text object.
    Every insertion point is a text object (like every character).
    Example 2:
    A table comes into play:
    The text frame is still selected.
    And the following code will move the anchored object (indeed the character) to the table:
    var myTextFrame = app.selection[0];
    var myTable = myTextFrame.parentStory.tables[0];
    myTextFrame.characters[0].move(LocationOptions.AFTER, myTable.cells[0].insertionPoints[0]);
    Situation after executing the snippet:
    Hope that helps,
    Uwe

  • Extract All Embedded Files in All Folders and Save Each? Copy/Paste from PDF to Word?

    I have most of what I need here, but I’m missing 2 important pieces. 
    #1)  I want to copy/paste from all PDF files in a folder and paste the copied data into a single Word file. 
    It works fine if I have ONLY Word docs in my folder.  When I have PDF files and Word files, the contents of the Word files are copied in fine, but the contents of the PDF files seem to come in as Chinese, and there is no Chinese in
    the PDF, so I have no idea where that’s coming from.
    #2)  I want to extract all embedded files (in all my Word files) and save the extracted/opened file into the folder.  Some embedded files are PDFs and some are Excel files.
    Here the code that I’m working with now.
    Sub Foo()
    Dim i As Long
    Dim MyName As String, MyPath As String
    Application.ScreenUpdating = False
    Documents.Add
    MyPath = "C:\Users\001\Desktop\Test\" ' <= change this as necessary
    MyName = Dir$(MyPath & "*.*") ' not *.* if you just want doc files
    On Error Resume Next
    Do While MyName <> ""
    If InStr(MyName, "~") = 0 Then
    Selection.InsertFile _
    FileName:="""" & MyPath & MyName & """", _
    ConfirmConversions:=False, Link:=False, _
    Attachment:=False
    Dim Myshape As InlineShape
    Dim IndexCount As Integer
    IndexCount = 1
    For Each Myshape In ActiveDocument.InlineShapes
    If Myshape.AlternativeText = PDFname Then
    ActiveDocument.InlineShapes(IndexCount).OLEFormat.Activate
    End If
    IndexCount = IndexCount + 1
    Next
    Selection.InsertBreak Type:=wdPageBreak
    End If
    On Error Resume Next
    Debug.Print MyName
    MyName = Dir ' gets the next doc file in the directory
    Loop
    End Sub
    If this has to be done using 2 Macros, that’s fine. 
    If I can do it in 1, that’s great too.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Hi ryguy72,
    >>When I have PDF files and Word files, the contents of the Word files are copied in fine, but the contents of the PDF files seem to come in as Chinese, and there is no Chinese in the PDF, so I have no idea where that’s coming from.<<
    Based on the code, you were insert the file via the code Selection.InsertFile. I am trying to reproduce this issue however failed. I suggest that you insert the PDF file manually to see whether this issue relative to the specific file. You can insert PDF
    file via Insert->Text->Object->Text from file.
    If this issue also could reproduced manually, I would suggest that you reopen a new thread in forum to narrow down whether this issue relative to the specific PDF file or Word application.
    >> I want to extract all embedded files (in all my Word files) and save the extracted/opened file into the folder.  Some embedded files are PDFs and some are Excel files.<<
    We can save the embedded spreadsheet via Excel object model. Here is an example that check the whether the inlineshape is an embedded workbook and save it to the disk for you reference:
    If Application.ActiveDocument.InlineShapes(1).OLEFormat.ClassType = "Excel.Sheet.12" Then
    Application.ActiveDocument.InlineShapes(1).OLEFormat.DoVerb xlPrimary
    Application.ActiveDocument.InlineShapes(1).OLEFormat.Object.SaveAs "C:\workbook1.xlsx"
    Application.ActiveDocument.InlineShapes(1).OLEFormat.Object.Close
    End If
    And since the Word object model doesn't provide API to save the embedded PDF, I would suggest that you get more effective response from PDF support forum to see whether it supports automation. If yes, we can export the PDF as embedded spreadsheet like code
    absolve.
    Hope it is helpful.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Copy pasting rows in isync-d files goes wrong

    I think I have hit an ugly bug... Here is the scenario:
    - I take/create a sheet on numbers on my Mac (running Mountain Lion with Numbers '09, version 2.3 (554))
    - I save this in iCloud, syncing with numbers on my iPad (iPad mini, running the latest version of IOS)
    - I reopen the file on my Mac, I add a few rows, I then copy a bunch of rows somewhere else, and paste it in the newly inserted rows.
    Then something goes terribly wrong. The paste does not occur; in some cases numbers hang, in some cases it destroys the full sheet. I cannot even revert, it gives me an error message whereby 'the file cannot be opened', or something similar.
    Put it another way: the only way I can use icloud syncing for my number sheets is if I do not structurally change the sheet. :-(

    Jerry,
    you are right, it was not clear. I did the same action on a file that did not go through icloud, and things were fine. I tried it with two different files.
    To make it clear, here are the flows
    A on Mac -> duplicate to C -> save it on icloud -> look at it, change some value on iPad -> edit it on Mac with copy paste -> fail
    A on Mac -> duplicate to M -> edit on Mac with copy paste -> works
    I duly update systems and apps every time I am notified both on Mac and on my iPad Mini.
    Ivan

  • Copy/Paste/Clipboard Problem; Pastes only as SVG Code

    I have Illustrator CC installed, as well as Illustrator CS6, running Windows 7 x64, latest patchlevel. When I try to copy and paste objects in Illustrator CC, I always get a SVG code. I draw a simple rectangular, copy it, paste it, it's not pasted as a rectangular, it's pasted as SVG code. Same with an embedded JPEG. Copy it. paste it. et voila, SVG code...
    In Illustrator CS6 everything works as i would expect it. Highlight object, cmd+c, cmd+v, ok.
    In CC, highlight object, cmd+c, cmd+v => svg code [<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In  --> etc. pp.] This always happens, no matter where (copy in illustrator cc, paste in the same illustrator document, word, photoshop, etc) or what (drawn object, jpeg, embedded, linked, gif).. I've tried different clipboard settings in Illustrator CC, it makes no difference.
    HELP!

    Of cause it is, but still I think it's a bug.
    I don't think it should work this way. First, Include SVG Code to me is not equal to Replace copied objects by SVG Code. When I copy an object from an Illustrator file and then try to paste it back into an Illustrator file, why should I get code instead? Second, that code was not pasted every time. Just about every second or third time. Sometimes it worked with a single object, sometimes to get that SVG code I had to copy/paste multiple objects, while pasting single objects worked as expected. So, to me it looks like a bug.
    And anyway, even if this function is supposed to replace objects with code, it should not be ON by default, not all of Illustrator users are developers. My estimate, most of us are not, actually.

  • Vector COPY/PASTE..wmf..svg..emf etc

    Hello:)
    Im looking for a component to integrate in an application to copy/paste or import/export vectors between programs.
    If theres someone that can assist me, will be great.
    Is it possible that someone has the file structure /source code for emf/wmf ??
    Thanks for any consideration
    [email protected]
    Please email directis you can really assist me.

    Of cause it is, but still I think it's a bug.
    I don't think it should work this way. First, Include SVG Code to me is not equal to Replace copied objects by SVG Code. When I copy an object from an Illustrator file and then try to paste it back into an Illustrator file, why should I get code instead? Second, that code was not pasted every time. Just about every second or third time. Sometimes it worked with a single object, sometimes to get that SVG code I had to copy/paste multiple objects, while pasting single objects worked as expected. So, to me it looks like a bug.
    And anyway, even if this function is supposed to replace objects with code, it should not be ON by default, not all of Illustrator users are developers. My estimate, most of us are not, actually.

  • Copying an unknown Object

    I have an Object that I pull from a Hashtable. I don't know what type of Object it is, nor do I care. But I need to make a copy of it and .clone() is protected on Object.
    eg.
    Object obj1 = hashtable.get(key);
    Object obj2 = obj1.clone(); // WILL NOT COMPILE (even in a try block)
    Any ideas?

    If these objects were created by your code, then they each need to implement Cloneable and also implement a public clone() method. If you call the clone() method of Object via super.clone(), then it is a shallow copy and you'll need to copy any embedded objects yourself.
    Assuming that all the classes in your Hashtable implement a public clone() method, then you'll need to either cast the reference to the appropriate class , or else use reflection to invoke the clone method.
    e.gimport java.lang.reflect.*;
    Object obj = yourHashtable.get("key");
    try {
        Method meth = obj.getClass().getMethod("clone", null);
        try {
            Object x = meth.invoke(obj, null);
            ...do something with cloned object x...
        } catch (Exception ex) {
            System.out.println("cannot call clone method: " + ex);
    } catch (NoSuchMethodException nsmex) {
        System.out.println("No public clone method exists: " + nsmex);
    }

  • Copy/Paste graphic w/drop shadow to indesign - loses transparency

    See above image.. I made a vector version of our company logo in illustrator (all programs referenced are cs5 btw) and it looks great, but when I copy and paste from Illustrator to InDesign, it loses the transparency around the logo. If I place the logo instead, it works fine. The trouble is there are about 16 variations of the logo, and its MUCH easier to copy/paste from one aggregate file instead of having many different logo files to place.
    Background on how the logo was created: The inner circle area is multiple different gradient layers (some with transparency masks as well). The white line around the outside is an expanded stroke, and it had a drop shadow effect applied (Stylize menu), which I expanded so it would scale properly when scaling the logo up and down. Here is a link to download the logo: download logo
    Q: Is there any way to make InDesign preserve the transparency when I copy and paste?
    Would be eternally grateful if someone has a solution that allows me to copy/paste!

    I agree with Bob's suggestion to use separate "layer groups" in your logo file for different styles. I also use separate layers inside InDesign to "multi-purpose" company documents with different backgrounds, graphics, and content. But that's the only way I use layers inside InDesign – Not for general placement of image files! I also disagree with ability to copy and paste graphics from Illustrator with drop shadow. Here's an .ai logo which I quickly added Drop Shadow to in Illustrator CS4, and then a Copy and Paste into InDesign CS4 document. Best workflow practice is to 'Place' image files as Bob suggests, linking them from a separate file folder.
    For something "quick and dirty" I see no problem with Copy and Paste, but your success may vary based on OS, and CS versions you are using!  Sometimes it is wiser to take a few shortcuts to hit rather than miss that deadline!

Maybe you are looking for