Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

sglab (TechnicalUser)
19 Oct 05 12:34
Hello everyone,

I hope somebody could help me with my problem.
I need to be able to extract file(s) embedded in Word document or RTF file and displayed as icon, and save it to specified location.
This is a general idea. Embedded file(s) could be of diferrent formats: Microsoft Office suite files, Adobe, images and so on.
I alredy make it work with embedded Word documents, but having problems with PDFs and ZIPs, for example. So I need some generic way to do that.

Any help would be greatly appreciated.

Thank you in advance.
sglab (TechnicalUser)
20 Oct 05 9:20
Is there anybody out there?

Guys, it's kind of an emergency.

Thanks.
TonyJollans (Programmer)
20 Oct 05 10:09
Hi sglab,

What do you do for Word files - and what problems do you have using the same code for other files?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress

sglab (TechnicalUser)
20 Oct 05 10:32
Hi Tony,

Thanks for your response.
Below is a piece of code - just a few lines to try to get it work:

CODE

 Dim iShape As InlineShape
 Dim objType As String
 Dim emDoc As Object
 Dim icLab As String
 
  
 For Each iShape In ActiveDocument.InlineShapes
  icLab = Mid(iShape.OLEFormat.IconLabel, InStrRev (iShape.OLEFormat.IconLabel, "\") + 1)
  objType = iShape.OLEFormat.ClassType
  iShape.OLEFormat.ActivateAs (objType)
  iShape.OLEFormat.Open
  Set emDoc = iShape.OLEFormat.Object
  emDoc.SaveAs "C:\" & icLab
  emDoc.Close
  Set emDoc = Nothing
      
 Next iShape


This code works for embedded Word docs because, I think the line in red returns object native to Word and SaveAs method is native to it to. But when it comes to, say PDF file, which was even inserted as a package and not as OLEObject, I don't seem to find any way to work with it.
The same red line returns an error.

Thanks.
 
TonyJollans (Programmer)
20 Oct 05 11:08
Hi sglab,

Yes, you are more or less correct.

You cannot do it generically the way you are doing it (I think you'ld be better off using DoVerb rather than ActivateAs and Open - but it won't help the generic case). What you are doing relies on you knowing how to interact with the particular class which may be OK if you only have a couple of types and know what they are but in general, unless (a) the Class supports Automation and (b) you know the commands to issue this can't work.

You could copy the object and paste it in the folder you want it in (not that I know the code for that off the top of my head but PHV will if he's around) but that will only work for some objects - others I think rely totally on you knowing what they are and interacting with them through the appropriat eapplication which, as I said, may not be possible. If all  your objects have been created from files (rather than as new and possibly not proper file types - for example, Excel Worksheet) then you might be able to do it this way - if so, come back and I'll try and root out the script that's needed.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress

sglab (TechnicalUser)
20 Oct 05 12:15
Hi Tony,

>>>You cannot do it generically the way you are doing it...
unless (a) the Class supports Automation and (b) you know the commands to issue


Well, I totally understand that and that's why I posted my question. Opening these files and re-saving them was never my choice. It's just I can't find in tons of Office objects and methods the one that could help me do what you said later:

>>>You could copy the object and paste it in the folder you want it in

I hope of course, that you'll think of something and somebody like PHV will join discussion. So for now, thanks a lot for your help and I go back and try to knock this thing out.

Best regards.
Helpful Member!  mintjulep (TechnicalUser)
20 Oct 05 13:35
As a cheat, perhaps you could create a new word document, embed the object in the new (otherwise empty) document, and save the new document with the embedded object.

That way you don't have to worry about what the object's native application is.  It also gets around the "scrap" object problem that you will have with .pdf files otherwise.
sglab (TechnicalUser)
20 Oct 05 14:19
Hi mintjulep,

Thanks for your input.
Maybe I just didn't fully understand what you were trying to say, but I do need to extract these native embedded files. Not to create another word document with embedded objects.
Could you come up with a few lines of code to illustrate this approach?
And also I need to make it efficient since I'm talking about quite a few such documents with embedded files. So I think speed is also an issue here.

Thanks.
mintjulep (TechnicalUser)
20 Oct 05 14:56
sglab,

If you need to save the embedded file object as a file with the proper extension of the object's native application, then my suggested cheat won't work for you.

I was playing around with a similar need some time ago, but got main tracked back to my real job, and never got anthing working.

One problem I had was with .pdf files.  Attempting to extract an embedded .pdf resulted in a "scrap" object, and even though this could be saved with the .pdf extension, Adobe failed to recognize it.  You may run into similar problems with other types.
sglab (TechnicalUser)
20 Oct 05 15:22
mintjulep,

Yes, I do need to have these embedded files saved in their native format, which could be anything. So the approach has to be as generic as possible.
Basically we're processing Outlook mailboxes where emails could have attachments, which in turn could have embedded files; and we need to be able to catch these and process them as well.
As far as "scrap" objects I've encountered them, too. Have no idea what to do with them.

So, I guess I'm back to square one.

Thank you.

Best regards.
fumei (TechnicalUser)
21 Oct 05 0:51
I hope someone comes up with something, because I do not think this is fully possible.  And I would like to be wrong.

Gerry

Helpful Member!  FaneDuru (TechnicalUser)
21 Oct 05 3:00
     One generic way may be putting the object in Clibpoard, using API to find the type and Pate it (not so easy)...
     The scrap (.shs) problem must be solved, too.

    Fane Duru
mintjulep (TechnicalUser)
21 Oct 05 6:30
A collegue of mine has also looked into this, and concluded that it is not possible.

I think my suggested cheat may be the best work-around.  You could add:

CODE

public sub autoopen()
activedocument.inlineshapes.item (1).activate
end sub

to the new container document, which would open the embedded object when the document opens.
sglab (TechnicalUser)
21 Oct 05 9:41
Thank you guys for your replies.

Whoa, I'm even rhyming. I think this is consequences of my battle with this task.

FaneDuru, could you illustrate your idea by pasting a few lines. I really don't know how embedded file can be put on Clipboard. As far as I remember from previous experiments with VBA, it (VBA) has access to Clipboard only through DataObject, which only supports text format. So may be it should be done in VB and not from within Word? What API are you referring to? Also, how Scrap object could be taken care of?  

mintjulep, you're right Activate method does open embebbed file in proper application, at least I know it's true for DOCs, PDFs and ZIPs, but the problem for me is that I don't know how to manipulate them - save with the correct file name (the one that's shown in the icon label) when IconLabel property doesn't return the file's name especially when ClassType is Package; close application they were opened with. And again, why would I need to create a new container document since I already have one?

Thank you.
mintjulep (TechnicalUser)
21 Oct 05 16:32
sglab,

I'm guilty of projecting my needs on your unknown to me application.

In my case various submittals come in embedded in a word doc.  The word doc is the transmittal letter.  We want to file each submitted item separately, so the new container document works for us.
FaneDuru (TechnicalUser)
24 Oct 05 3:08
In order to put the object in Clipboard:

CODE

ActiveDocument.InlineShapes(1).Select
Selection.Copy

If you paste now in a folder (manualy) you will save the object (like it is - for pictures). For documents you will obtain so named scrap document (.shs).

There are APIs able do paste from Clipboard (finding previously the object format...).
For instance:

CODE

Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" _
    (ByVal wFormat As Long) As Long
Private Declare Function RegisterClipboardFormat Lib "user32" Alias _
    "RegisterClipboardFormatA" (ByVal lpString As String) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, _
    ByVal hMem As Long) As Long
  Using such API may be it is possible to paste...

  Fane Duru

sglab (TechnicalUser)
27 Oct 05 9:01
mintjulep and FaneDuru,

I have to apologize for delayed response: had a knee surgery on Monday and wasn't really up to doing anything. Just decided to check if there was any progress in the matter.
Thank you guys for trying to help. I will definitely continue to try to find the solution, using your input or something else. Just not now.

Best regards.

Thanks again.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close