I import documents from my Genealogy program that require the image links be
reset (Edit>Links dialog). I have tried various ways of recording this dialog
to a macro but nothing is recorded. I appears that the dialog window for
resetting links may not support macro recording??? If so how could this be
done?
--
Bob Berg

Re: Macro To Set Image Links by Jezebel

Jezebel
Mon Sep 11 20:58:15 CDT 2006

Iterate the Shapes collection and set the links directly --

Dim pShape as Word.Shape

For each pShape in ActiveDocument.Shapes
pShape.LinkFormat.SourcePath = "..."
Next

You'll need to be more sophisticated than this if a) not all your shapes are
linked images (in which case text they type, etc), or b) the path is
different for different graphics (in which case you'll need to look at the
SourceName and apply whatever logic you need).




"Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
>I import documents from my Genealogy program that require the image links
>be
> reset (Edit>Links dialog). I have tried various ways of recording this
> dialog
> to a macro but nothing is recorded. I appears that the dialog window for
> resetting links may not support macro recording??? If so how could this be
> done?
> --
> Bob Berg



Re: Macro To Set Image Links by BobBerg

BobBerg
Mon Sep 11 21:19:01 CDT 2006

I must be missing something, I get message:
Compile error.
"Can't assign to read only property" with "source path =" highlighted in
debugger.
--
Bob Berg


"Jezebel" wrote:

> Iterate the Shapes collection and set the links directly --
>
> Dim pShape as Word.Shape
>
> For each pShape in ActiveDocument.Shapes
> pShape.LinkFormat.SourcePath = "..."
> Next
>
> You'll need to be more sophisticated than this if a) not all your shapes are
> linked images (in which case text they type, etc), or b) the path is
> different for different graphics (in which case you'll need to look at the
> SourceName and apply whatever logic you need).
>
>
>
>
> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
> >I import documents from my Genealogy program that require the image links
> >be
> > reset (Edit>Links dialog). I have tried various ways of recording this
> > dialog
> > to a macro but nothing is recorded. I appears that the dialog window for
> > resetting links may not support macro recording??? If so how could this be
> > done?
> > --
> > Bob Berg
>
>
>

Re: Macro To Set Image Links by Jezebel

Jezebel
Mon Sep 11 22:12:42 CDT 2006

Sorry, my mistake. You have to set the SourceFullName property. If all the
files are linking to a new folder, use

Dim pShape as Word.Shape
Const pNewFolder = "C:\...\"

For each pShape in ActiveDocument.Shapes
pShape.LinkFormat.SourceFullName = pNewFolder &
pShape.LinkFormat.SourceName
Next



"Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
news:FBED1545-1306-46FD-BF28-087CE1721C88@microsoft.com...
>I must be missing something, I get message:
> Compile error.
> "Can't assign to read only property" with "source path =" highlighted in
> debugger.
> --
> Bob Berg
>
>
> "Jezebel" wrote:
>
>> Iterate the Shapes collection and set the links directly --
>>
>> Dim pShape as Word.Shape
>>
>> For each pShape in ActiveDocument.Shapes
>> pShape.LinkFormat.SourcePath = "..."
>> Next
>>
>> You'll need to be more sophisticated than this if a) not all your shapes
>> are
>> linked images (in which case text they type, etc), or b) the path is
>> different for different graphics (in which case you'll need to look at
>> the
>> SourceName and apply whatever logic you need).
>>
>>
>>
>>
>> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
>> news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
>> >I import documents from my Genealogy program that require the image
>> >links
>> >be
>> > reset (Edit>Links dialog). I have tried various ways of recording this
>> > dialog
>> > to a macro but nothing is recorded. I appears that the dialog window
>> > for
>> > resetting links may not support macro recording??? If so how could this
>> > be
>> > done?
>> > --
>> > Bob Berg
>>
>>
>>



Re: Macro To Set Image Links by BobBerg

BobBerg
Tue Sep 12 08:39:02 CDT 2006

Must still be doing something wrong - macro doesn't link anything. I have
tried a very simple two image document with images in same folder as doc but
links are still not reset.
--
Bob Berg


"Jezebel" wrote:

> Sorry, my mistake. You have to set the SourceFullName property. If all the
> files are linking to a new folder, use
>
> Dim pShape as Word.Shape
> Const pNewFolder = "C:\...\"
>
> For each pShape in ActiveDocument.Shapes
> pShape.LinkFormat.SourceFullName = pNewFolder &
> pShape.LinkFormat.SourceName
> Next
>
>
>
> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> news:FBED1545-1306-46FD-BF28-087CE1721C88@microsoft.com...
> >I must be missing something, I get message:
> > Compile error.
> > "Can't assign to read only property" with "source path =" highlighted in
> > debugger.
> > --
> > Bob Berg
> >
> >
> > "Jezebel" wrote:
> >
> >> Iterate the Shapes collection and set the links directly --
> >>
> >> Dim pShape as Word.Shape
> >>
> >> For each pShape in ActiveDocument.Shapes
> >> pShape.LinkFormat.SourcePath = "..."
> >> Next
> >>
> >> You'll need to be more sophisticated than this if a) not all your shapes
> >> are
> >> linked images (in which case text they type, etc), or b) the path is
> >> different for different graphics (in which case you'll need to look at
> >> the
> >> SourceName and apply whatever logic you need).
> >>
> >>
> >>
> >>
> >> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> >> news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
> >> >I import documents from my Genealogy program that require the image
> >> >links
> >> >be
> >> > reset (Edit>Links dialog). I have tried various ways of recording this
> >> > dialog
> >> > to a macro but nothing is recorded. I appears that the dialog window
> >> > for
> >> > resetting links may not support macro recording??? If so how could this
> >> > be
> >> > done?
> >> > --
> >> > Bob Berg
> >>
> >>
> >>
>
>
>

Re: Macro To Set Image Links by Jean-Guy

Jean-Guy
Tue Sep 12 16:05:17 CDT 2006

Bob Berg was telling us:
Bob Berg nous racontait que :

> Must still be doing something wrong - macro doesn't link anything. I
> have tried a very simple two image document with images in same
> folder as doc but links are still not reset.
>
>> Sorry, my mistake. You have to set the SourceFullName property. If
>> all the files are linking to a new folder, use
>>
>> Dim pShape as Word.Shape
>> Const pNewFolder = "C:\...\"
>>
>> For each pShape in ActiveDocument.Shapes
>> pShape.LinkFormat.SourceFullName = pNewFolder &
>> pShape.LinkFormat.SourceName
>> Next
>>

I have just created a document with two linked images in it (Insert >
Picture... > From File), located at
"X:\Office 2003\Images\"

Then, I Cut/Pasted the images to
"X:\Office 2003\Test\"

Finally, I ran this code:

Dim pShape As Word.Shape
Const pNewFolder = "X:\Office 2003\Test\"

For Each pShape In ActiveDocument.Shapes
pShape.LinkFormat.SourceFullName = pNewFolder &
pShape.LinkFormat.SourceName
Next

Everything worked as expected.

So either there is something wrong with your document or your method.

Can you try just as I have done to make sure you are using the code
properly.
If it works, then there is something wrong with your approach. Try to
retrace your steps and make sure the images are indeed located where they
should be.

You write that the images aren't being linked. Is the code running without
error? Are the image inline or floating?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Macro To Set Image Links by Jezebel

Jezebel
Tue Sep 12 16:42:55 CDT 2006

Are you images floating or inline? If they are inline, replace
"ActiveDocument.Shapes" with "ActiveDocument.InlineShapes"





"Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
news:3DB06037-2252-4A21-9B78-6A610EA73D39@microsoft.com...
> Must still be doing something wrong - macro doesn't link anything. I have
> tried a very simple two image document with images in same folder as doc
> but
> links are still not reset.
> --
> Bob Berg
>
>
> "Jezebel" wrote:
>
>> Sorry, my mistake. You have to set the SourceFullName property. If all
>> the
>> files are linking to a new folder, use
>>
>> Dim pShape as Word.Shape
>> Const pNewFolder = "C:\...\"
>>
>> For each pShape in ActiveDocument.Shapes
>> pShape.LinkFormat.SourceFullName = pNewFolder &
>> pShape.LinkFormat.SourceName
>> Next
>>
>>
>>
>> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
>> news:FBED1545-1306-46FD-BF28-087CE1721C88@microsoft.com...
>> >I must be missing something, I get message:
>> > Compile error.
>> > "Can't assign to read only property" with "source path =" highlighted
>> > in
>> > debugger.
>> > --
>> > Bob Berg
>> >
>> >
>> > "Jezebel" wrote:
>> >
>> >> Iterate the Shapes collection and set the links directly --
>> >>
>> >> Dim pShape as Word.Shape
>> >>
>> >> For each pShape in ActiveDocument.Shapes
>> >> pShape.LinkFormat.SourcePath = "..."
>> >> Next
>> >>
>> >> You'll need to be more sophisticated than this if a) not all your
>> >> shapes
>> >> are
>> >> linked images (in which case text they type, etc), or b) the path is
>> >> different for different graphics (in which case you'll need to look at
>> >> the
>> >> SourceName and apply whatever logic you need).
>> >>
>> >>
>> >>
>> >>
>> >> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
>> >> news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
>> >> >I import documents from my Genealogy program that require the image
>> >> >links
>> >> >be
>> >> > reset (Edit>Links dialog). I have tried various ways of recording
>> >> > this
>> >> > dialog
>> >> > to a macro but nothing is recorded. I appears that the dialog window
>> >> > for
>> >> > resetting links may not support macro recording??? If so how could
>> >> > this
>> >> > be
>> >> > done?
>> >> > --
>> >> > Bob Berg
>> >>
>> >>
>> >>
>>
>>
>>



Re: Macro To Set Image Links by BobBerg

BobBerg
Tue Sep 12 17:09:02 CDT 2006

Images are inline so used:
Dim pShape As Word.Shape
Const pNewFolder = "c:\tmg6\reports\"
For Each pShape In ActiveDocument.InlineShapes
pShape.LinkFormat.SourceFullName = pNewFolder & pShape.LinkFormat.SourceName
Next

I verified folder for images and the images by name in the folder. It is the
same as the document is in. I can go to edit>link, select all the images,
update and that works just fine.

I use the following routine after the photos are linked and showing to
resize, it works just fine:

Sub ResizePhotos()
Dim PreferredHeight As Integer
Dim MaximWidth As Integer
PreferredHeight = InputBox("Enter height in points (72pts/in,
28pts/cm)", , 108)
MaximWidth = InputBox("Enter maximum allowable width in points", , 144)
For Each iShape In ActiveDocument.InlineShapes
With iShape
ImageWidth = .Width
ImageHeight = .Height
NewHeight = PreferredHeight
NewWidth = Round(NewHeight * ImageWidth / ImageHeight)
If NewWidth > MaximWidth Then
NewWidth = MaximWidth
NewHeight = Round(NewWidth * ImageHeight / ImageWidth)
End If
.Height = NewHeight
.Width = NewWidth
End With
Next
End Sub
--
Bob Berg


"Jezebel" wrote:

> Are you images floating or inline? If they are inline, replace
> "ActiveDocument.Shapes" with "ActiveDocument.InlineShapes"
>
>
>
>
>
> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> news:3DB06037-2252-4A21-9B78-6A610EA73D39@microsoft.com...
> > Must still be doing something wrong - macro doesn't link anything. I have
> > tried a very simple two image document with images in same folder as doc
> > but
> > links are still not reset.
> > --
> > Bob Berg
> >
> >
> > "Jezebel" wrote:
> >
> >> Sorry, my mistake. You have to set the SourceFullName property. If all
> >> the
> >> files are linking to a new folder, use
> >>
> >> Dim pShape as Word.Shape
> >> Const pNewFolder = "C:\...\"
> >>
> >> For each pShape in ActiveDocument.Shapes
> >> pShape.LinkFormat.SourceFullName = pNewFolder &
> >> pShape.LinkFormat.SourceName
> >> Next
> >>
> >>
> >>
> >> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> >> news:FBED1545-1306-46FD-BF28-087CE1721C88@microsoft.com...
> >> >I must be missing something, I get message:
> >> > Compile error.
> >> > "Can't assign to read only property" with "source path =" highlighted
> >> > in
> >> > debugger.
> >> > --
> >> > Bob Berg
> >> >
> >> >
> >> > "Jezebel" wrote:
> >> >
> >> >> Iterate the Shapes collection and set the links directly --
> >> >>
> >> >> Dim pShape as Word.Shape
> >> >>
> >> >> For each pShape in ActiveDocument.Shapes
> >> >> pShape.LinkFormat.SourcePath = "..."
> >> >> Next
> >> >>
> >> >> You'll need to be more sophisticated than this if a) not all your
> >> >> shapes
> >> >> are
> >> >> linked images (in which case text they type, etc), or b) the path is
> >> >> different for different graphics (in which case you'll need to look at
> >> >> the
> >> >> SourceName and apply whatever logic you need).
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> "Bob Berg" <BobBerg@discussions.microsoft.com> wrote in message
> >> >> news:12FB6123-C84D-433D-9398-2CA972B8EC17@microsoft.com...
> >> >> >I import documents from my Genealogy program that require the image
> >> >> >links
> >> >> >be
> >> >> > reset (Edit>Links dialog). I have tried various ways of recording
> >> >> > this
> >> >> > dialog
> >> >> > to a macro but nothing is recorded. I appears that the dialog window
> >> >> > for
> >> >> > resetting links may not support macro recording??? If so how could
> >> >> > this
> >> >> > be
> >> >> > done?
> >> >> > --
> >> >> > Bob Berg
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Re: Macro To Set Image Links by Jean-Guy

Jean-Guy
Tue Sep 12 19:20:37 CDT 2006

Bob Berg was telling us:
Bob Berg nous racontait que :

> Images are inline so used:
> Dim pShape As Word.Shape
> Const pNewFolder = "c:\tmg6\reports\"
> For Each pShape In ActiveDocument.InlineShapes
> pShape.LinkFormat.SourceFullName = pNewFolder &
> pShape.LinkFormat.SourceName Next

I am guessing it did not work.. You never mention that fact in your reply.
By reading between the lines, I guess you still have a problem, it is more
helpful to those helping you when you are explicit... ;-)

In any case, I see that you changed the Shapes to InlineShape as suggested
by Jezebel, but you did not change the variable assignment, try also
changing:

Dim pShape As Word.Shape

for

Dim pShape As Word.InlineShape

Otherwise you are telling Word to look for a Shape in the InlineShape
collection, and there aren't any! :-)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Macro To Set Image Links by BobBerg

BobBerg
Wed Sep 13 04:25:01 CDT 2006

I am now trying:

Sub TMGPhotoLink()
Dim pShape As Word.InlineShape
Const pNewFolder = "c:\tmg6\reports\"
For Each pShape In ActiveDocument.InlineShapes
pShape.LinkFormat.SourceFullName = pNewFolder & pShape.LinkFormat.SourceName

Next

End Sub

Still doesn't work, by the way using Word 2003

Bob Berg
--
Bob Berg


"Jean-Guy Marcil" wrote:

> Bob Berg was telling us:
> Bob Berg nous racontait que :
>
> > Images are inline so used:
> > Dim pShape As Word.Shape
> > Const pNewFolder = "c:\tmg6\reports\"
> > For Each pShape In ActiveDocument.InlineShapes
> > pShape.LinkFormat.SourceFullName = pNewFolder &
> > pShape.LinkFormat.SourceName Next
>
> I am guessing it did not work.. You never mention that fact in your reply.
> By reading between the lines, I guess you still have a problem, it is more
> helpful to those helping you when you are explicit... ;-)
>
> In any case, I see that you changed the Shapes to InlineShape as suggested
> by Jezebel, but you did not change the variable assignment, try also
> changing:
>
> Dim pShape As Word.Shape
>
> for
>
> Dim pShape As Word.InlineShape
>
> Otherwise you are telling Word to look for a Shape in the InlineShape
> collection, and there aren't any! :-)
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>

Re: Macro To Set Image Links by Jean-Guy

Jean-Guy
Wed Sep 13 06:07:18 CDT 2006

Bob Berg was telling us:
Bob Berg nous racontait que :

> I am now trying:
>
> Sub TMGPhotoLink()
> Dim pShape As Word.InlineShape
> Const pNewFolder = "c:\tmg6\reports\"
> For Each pShape In ActiveDocument.InlineShapes
> pShape.LinkFormat.SourceFullName = pNewFolder &
> pShape.LinkFormat.SourceName
>
> Next
>
> End Sub
>
> Still doesn't work, by the way using Word 2003

I have just tried the code you posted by doing the following:

1) Created a blank document;
2) Added two linked inline images located at:
"X:\Office 2003\OriginalFolder\"
(To make sure they are inline, select an image, do SHIFT-F9
and you should see an INCLUDEPICTURE field instead of
the image, do F9 to update the image and hide the field code)
3) Moved the images to:
"X:\Office 2003\NewFolder\"
4) Updated the images in the document;
5) As expected, the images were replaced by a red "X" in a white rectangle;
6) Ran this code:

Sub TMGPhotoLink()

Dim pShape As Word.InlineShape

Const pNewFolder = "X:\Office 2003\NewFolder\"

For Each pShape In ActiveDocument.InlineShapes
pShape.LinkFormat.SourceFullName = pNewFolder & _
pShape.LinkFormat.SourceName
Next

End Sub

7) The images were automatically updated;
8) Just to be sure, I selected the images and hit SHIFT-F9 to see the field
code;
9) The new path was there.

You only stated "Still doesn't work". This doesn't give us much to go on.
You have to be more explicit.
Is the macro running seemingly OK, but images are still represented by
red "X"'s?
Do you get an error message?

I would suggest you try the 9 steps above with a brand new document.
If it works, then compare those 9 steps with you have done with your current
document. What is the difference?
If it does not, post back describing exactly what you have done and the
on-screen results.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org