Linking images to a document doesn't show them 
Author Message
 Linking images to a document doesn't show them

Hi all

I have written a macro that will look in a given directory and its
subdirectories for images, and will import them into a new document. The
macro will also add the full path to the image below the image.

All of this works, except for one small thing: the user can choose to Link
the files or to embed the files. When embedding, it works.

When linking however, it doesn't. Word does spend a whole lot of time
executing the macro (much longer than when embedding), the file gets saved
and has about the same size as the same document with embedded images, but I
can't see the images.

When I close and reopen the document, Word gives me approximately the same
wordcount (you know, in the statusbar) as the document with embedded
pictures. However, when I ask for a wordcount (Tools menu) it returns zero.
When I save the file after that wordcount and reopen it, the wordcount in
the statusbar also says 0 words. The size of the document itself doesn't
change.

Below is an excerpt of my code (this code gets called from another function,
in a loop):

------------------------------

Private Sub DoInsert(ByVal strPicture As String, ByVal blnLink As Boolean)
    '
    ' Move to the last character: new insertion point
    Selection.SetRange m_objDocument.Characters.Count,
m_objDocument.Characters.Count
    ' Insert the next picture at the insertion point
    If (Not blnLink) Then
        m_objDocument.InlineShapes.AddPicture strPicture, blnLink, , _
            m_objDocument.range(m_objDocument.Characters.Count - 1,
m_objDocument.Characters.Count - 1)
    Else
        m_objDocument.InlineShapes.AddOLEObject , strPicture, True, False, ,
, , _
            m_objDocument.range(m_objDocument.Characters.Count - 1,
m_objDocument.Characters.Count - 1)
    End If
    '
    Selection.SetRange m_objDocument.Characters.Count - 1,
m_objDocument.Characters.Count
    ' Insert the name of the file
    Selection.InsertAfter vbCrLf & strPicture
    ' Move to the last position
    Selection.SetRange m_objDocument.Characters.Count,
m_objDocument.Characters.Count
    ' Insert a page break
    Selection.InsertBreak wdPageBreak
    '
End Sub

------------------------

What I find strange is that I can't even see the path to the image. No
errors occur, and when I debug the code everything seems fine.

Any help?

Sven.



Tue, 28 Jan 2003 03:00:00 GMT  
 Linking images to a document doesn't show them
Hi Sven,

I don't know, but I'm wondering... when you insert a linked picture, you're
actually inserting an IncludePicture field. It's possible (especially since
you're working with ranges and characters!) that you're actually putting
everything within the first set of field brackets.

Take one of your test files, press Alt+F9, and what do you see?

Quote:
> All of this works, except for one small thing: the user can choose to Link
> the files or to embed the files. When embedding, it works.

> When linking however, it doesn't. Word does spend a whole lot of time
> executing the macro (much longer than when embedding), the file gets saved
> and has about the same size as the same document with embedded images, but I
> can't see the images.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

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



Thu, 30 Jan 2003 03:00:00 GMT  
 Linking images to a document doesn't show them

Hi Cindy

Thanks for the answer. I think you might be on to something: when I press Alt+F9, it shows

{ <hard return>
<page break>
<space><hard return>
<path to the first picture>EMBED Package<space><space>}{<hard return>
<page break>

...

Something like

{

D:\My Pictures\plane_fast.gifEMBED Package  }{

Everything is in gray (obviously). So I guess what I'm doing is including everything in the field code for the embedded image and that's what goes wrong?

How can I improve my code?

Thanks for your help

Sven.


Quote:
> Hi Sven,

> I don't know, but I'm wondering... when you insert a linked picture, you're
> actually inserting an IncludePicture field. It's possible (especially since
> you're working with ranges and characters!) that you're actually putting
> everything within the first set of field brackets.

> Take one of your test files, press Alt+F9, and what do you see?

> > All of this works, except for one small thing: the user can choose to Link
> > the files or to embed the files. When embedding, it works.

> > When linking however, it doesn't. Word does spend a whole lot of time
> > executing the macro (much longer than when embedding), the file gets saved
> > and has about the same size as the same document with embedded images, but I
> > can't see the images.

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://go.compuserve.com/MSOfficeForum

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



Fri, 31 Jan 2003 03:00:00 GMT  
 Linking images to a document doesn't show them
Hi Sven,

Quote:
> So I guess what I'm doing is including everything in the
> field code for the embedded image and that's what goes
> wrong?

Yep.

You should be able to avoid this by working directly with
ranges. Here's some sample code that is not built into a
loop, but I stuck in a second repeat so that you could see
how it works:

Sub LoadNLabelPics()
    Dim ils As Word.InlineShape
    Dim rng As Word.Range
    Dim picPath As String

    picPath = "E:\CM\InsWrd\SDDiag\"
    Set rng = ActiveDocument.Range
    rng.Collapse wdCollapseEnd

'Start 1st repeat
    Set ils = ActiveDocument.InlineShapes.AddPicture( _
        FileName:=picPath & "SDDiag01.tif",
LinkToFile:=True, _
        SaveWithDocument:=False, Range:=rng)
    Set rng = ils.Range
    rng.Collapse wdCollapseEnd
    rng.Text = vbCr & "Caption for picture 1" & vbCr
    rng.Collapse wdCollapseEnd

'2nd repeat    
    Set ils = ActiveDocument.InlineShapes.AddPicture( _
        FileName:=picPath & "SDDiag02.tif",
LinkToFile:=True, _
        SaveWithDocument:=False, Range:=rng)
    Set rng = ils.Range
    rng.Collapse wdCollapseEnd
    rng.Text = vbCr & "Caption for picture 2" & vbCr
    rng.Collapse wdCollapseEnd

End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

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



Sat, 01 Feb 2003 03:00:00 GMT  
 Linking images to a document doesn't show them

Thank you very much,

you're too kind :-)

Regards
Sven.



Quote:
> Hi Sven,

> > So I guess what I'm doing is including everything in the
> > field code for the embedded image and that's what goes
> > wrong?

> Yep.

> You should be able to avoid this by working directly with
> ranges. Here's some sample code that is not built into a
> loop, but I stuck in a second repeat so that you could see
> how it works:

> Sub LoadNLabelPics()
>     Dim ils As Word.InlineShape
>     Dim rng As Word.Range
>     Dim picPath As String

>     picPath = "E:\CM\InsWrd\SDDiag\"
>     Set rng = ActiveDocument.Range
>     rng.Collapse wdCollapseEnd

> 'Start 1st repeat
>     Set ils = ActiveDocument.InlineShapes.AddPicture( _
>         FileName:=picPath & "SDDiag01.tif",
> LinkToFile:=True, _
>         SaveWithDocument:=False, Range:=rng)
>     Set rng = ils.Range
>     rng.Collapse wdCollapseEnd
>     rng.Text = vbCr & "Caption for picture 1" & vbCr
>     rng.Collapse wdCollapseEnd

> '2nd repeat
>     Set ils = ActiveDocument.InlineShapes.AddPicture( _
>         FileName:=picPath & "SDDiag02.tif",
> LinkToFile:=True, _
>         SaveWithDocument:=False, Range:=rng)
>     Set rng = ils.Range
>     rng.Collapse wdCollapseEnd
>     rng.Text = vbCr & "Caption for picture 2" & vbCr
>     rng.Collapse wdCollapseEnd

> End Sub

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://go.compuserve.com/MSOfficeForum

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



Sun, 02 Feb 2003 14:49:31 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. OLE object linked to an image doesn't display anything

2. Custom ActiveX Control Doesn't Show in Other Computer's Browsers

3. TreeView doesn''t show Plus/Minus expand/collapse indicators

4. Linked image does not show in PrintOut

5. Shape drops but doesn't show up.

6. My Form doesn't show in front of the calling Form

7. Overloaded New doesn't show up in the Inherited Form

8. Datagrid in ASP.Net - Grid doesn't show up on webpage

9. Select element doesn't show first option?

10. VisData doesn't show all records

11. Program doesn't show up in Alt-Tab Group

12. My app doesn't show in Taskbar

 

 
Powered by phpBB® Forum Software