Selection.InsertFile doesn't insert the picture in origianl docume

N

nmou

I have Word 2007 and run the following macro to insert sample.doc to current
blank document:

Selection.InsertFile FileName:="C:\sample.doc", Link:=False

The sample.doc contain a pciture ( the picture is jpeg, not a link and has
been saved in sample.doc.), I alwasy get a red cross at top left cornor of a
picture box, however, if I open sample.doc and try to run the macro again, I
can see picture. Is this a bug in Word 2007? It works fine in Word 2003
without open the sample.doc.
 
C

Cindy M.

Hi =?Utf-8?B?bm1vdQ==?=,
I have Word 2007 and run the following macro to insert sample.doc to current
blank document:

Selection.InsertFile FileName:="C:\sample.doc", Link:=False

The sample.doc contain a pciture ( the picture is jpeg, not a link and has
been saved in sample.doc.), I alwasy get a red cross at top left cornor of a
picture box, however, if I open sample.doc and try to run the macro again, I
can see picture. Is this a bug in Word 2007? It works fine in Word 2003
without open the sample.doc.
If you click on this picture box, then press F9, does that change anything?

If you press Alt+F9 that should display the field codes. What field information
do you see "behind" the picture box?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

nmou

Hi Cindy, thank you for your reply. When I hit F9, there is nothing change,
and when I hit Alt+F9, I got " {DOCVARIABLE GraphTitle \* MERGEFORMAT }"
above the picture box area. I went back to double check the "sample.doc" and
foud the same field codes. The "sample.doc" has been created programmatically
in C#, it contains a titile filed "Sample Graph Title", and below it there is
a picture. That's probably we saw the field codes. The following is sample
code to generate the "sample.doc"

// Updating the title
object Title = "GraphTitle";
oWordDoc.Variables.get_Item(ref Title).Value = "Sample Graph Title";
oWordDoc.Fields.Update();
// Inserting graph
Microsoft.Office.Interop.Word.InlineShape oInlineShape;
oInlineShape =
oWordDoc.Application.Selection.Range.InlineShapes.AddPicture(strPicFile, ref
m_oMissing, ref m_oMissing, ref m_oMissing);

I believe there is something wrong with the orignal document "Sample.doc"
because of creation in C#
 
C

Cindy M.

Thanks for the additional detail.

Just for the sake of completeness: if you try to insert the file via the UI,
instead of using code, do you see the same result?

How about if you create sample.doc in the UI (insert the jpeg "by hand"), save,
close, then try inserting it into another document? Do you see the same problem?

And if you try a different kind of file (other than jpeg) when creating
sample.doc do you continue to see the same problem, or does this picture show up
in the inserted file?

What I'm trying to do here is to narrow down where the problem is coming from. I
suspect it might be a result of the new "Escher" graphics engine in Office 2007,
that Word has only partially implemented...
When I hit F9, there is nothing change,
and when I hit Alt+F9, I got " {DOCVARIABLE GraphTitle \* MERGEFORMAT }"
above the picture box area. I went back to double check the "sample.doc" and
foud the same field codes. The "sample.doc" has been created programmatically
in C#, it contains a titile filed "Sample Graph Title", and below it there is
a picture. That's probably we saw the field codes. The following is sample
code to generate the "sample.doc"

// Updating the title
object Title = "GraphTitle";
oWordDoc.Variables.get_Item(ref Title).Value = "Sample Graph Title";
oWordDoc.Fields.Update();
// Inserting graph
Microsoft.Office.Interop.Word.InlineShape oInlineShape;
oInlineShape =
oWordDoc.Application.Selection.Range.InlineShapes.AddPicture(strPicFile, ref
m_oMissing, ref m_oMissing, ref m_oMissing);

I believe there is something wrong with the orignal document "Sample.doc"

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

nmou

Hi Cindy, finally, the problem is due to version compatibility, the
"sample.doc" and template were created in 2003, and they don't work well in
2007, so we recreated all doc and template in 2007 version and everything
works fine now. Thank you for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top