Solved

How to Embed Images in Word 2000 documents as OLE objects through VB6 code?

Posted on 2007-11-29
4
1,208 Views
Last Modified: 2013-11-25
Hi,

I've got a problem with the attached code. What I'm trying to do is loop through adding external files as images embedded in a word 2000 document in vb6 code.

In my code - below - you can see that I set the linktofile flag to be false....

srcRange.InlineShapes.AddOLEObject fileName:=exportPath, LinkToFile:=False, DisplayAsIcon:=False, range:=range

yet when I run the following code:

wordDoc.SaveAs sfd.fileName, AddToRecentFiles:=False

I get a word document created, with a subdirectory and all the image files stored in there - referenced by the parent word document.

Any help would be greatly appreciated!

Rick
Public Sub OnSavingWordDocument(ByVal wordDoc As Word.Document, ByVal doc As DOMDocument)
    Dim fso As New FileSystemObject
    Dim ts As TextStream
    Dim nodes As MSXML2.IXMLDOMNodeList
    Dim nodeCount As Long
    Dim srcRange As Word.range
    
    Set nodes = doc.selectNodes(mXPath)
    Set srcRange = wordDoc.Content
    For nodeCount = 1 To nodes.length Step 1
        If (FindToken(srcRange, mToken)) Then
            srcRange.Text = ""
            Dim exportPath As String
            exportPath = GetTempFile("cdxml")
            Set ts = fso.CreateTextFile(exportPath, True, True)
            ts.Write nodes(nodeCount - 1).Text
            ts.Close
            
            Dim range As Word.range
            Set range = srcRange
            srcRange.InlineShapes.AddOLEObject fileName:=exportPath, LinkToFile:=False, DisplayAsIcon:=False, range:=range
            srcRange.End = wordDoc.Content.End
            fso.DeleteFile exportPath, True
        End If
    Next nodeCount
End Sub
 
...
OnSavingWordDocument wordDoc, doc
wordDoc.SaveAs sfd.fileName, AddToRecentFiles:=False
...

Open in new window

0
Comment
Question by:rickbarnsley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20373927
Have you tried the InlineShapes.AddPicture method:

srcRange.InlineShapes.AddPicture exportPath

I'm not sure why the OLE object is creating links when you specify LinkToFile=False.  I'm not able to replicate that behaviour.  What kind of images are they?
0
 

Author Comment

by:rickbarnsley
ID: 20418661
Solved it -

I changed...
                    wordDoc.SaveAs sfd.fileName, AddToRecentFiles:=False
to
                    wordDoc.SaveAs sfd.fileName, FileFormat:=wdFormatDocument, AddToRecentFiles:=False

Can't explain it, but it works now! Cheers
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21000159
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to Classify of email (pdf attachments) 7 50
Run AutoHotkey script directly from Notepad++ 5 144
Create .bat File 16 73
add criteria to query in VB, Access 2003 2 32
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question