How can I programmatically relink OLE's in a Word document

C

Cevriye Kuntay

Hi!
I created a Microsoft Word document that contains dozens of linked objects
(OLE's). I am trying to change the path name in the "embedded objects"
within the Word. I want the macro to scan through each page in the document
and find each embedded object (which are linked to an excel file), then find
the pathname: "C:\drive\documents\file1.xls" and replace it with
"C:\drive\documents\file2.xls". I have the following as a beginnig point
but I could not finish it. This is my first attempt to write a VBA code. Any
help you could provide will be greatly appreciated. Here is my incomplete
code:

Sub ChangeSource()

Dim k As Long
'Create a variable to store the object reference string.
Dim strLink As String

With ActiveDocument
' Loop through all the floating shapes in document.
For k = 1 To .Shapes.Count
With .Shapes(k)
' If the shape's type is an OLE object then...
If .Type = msoLinkedOLEObject Then
' Change the path to new source and set the update
' type to Automatic.
With .LinkFormat
' Get the source path in a string
strLink = .SourceFullName
' Do something to strLink to modify:

'Code to modify strLink

.SourceFullName = strLink
.Update
End With
End If
End With
Next k

End With
 
J

Jean-Guy Marcil

Cevriye Kuntay was telling us:
Cevriye Kuntay nous racontait que :
Hi!
I created a Microsoft Word document that contains dozens of linked
objects (OLE's). I am trying to change the path name in the "embedded
objects" within the Word. I want the macro to scan through each page
in the document and find each embedded object (which are linked to an
excel file), then find the pathname: "C:\drive\documents\file1.xls"
and replace it with "C:\drive\documents\file2.xls". I have the
following as a beginnig point but I could not finish it. This is my
first attempt to write a VBA code. Any help you could provide will be
greatly appreciated. Here is my incomplete code:

Sub ChangeSource()

Dim k As Long
'Create a variable to store the object reference string.
Dim strLink As String

With ActiveDocument
' Loop through all the floating shapes in document.
For k = 1 To .Shapes.Count
With .Shapes(k)
' If the shape's type is an OLE object then...
If .Type = msoLinkedOLEObject Then
' Change the path to new source and set the update
' type to Automatic.
With .LinkFormat
' Get the source path in a string
strLink = .SourceFullName
' Do something to strLink to modify:

'Code to modify strLink

.SourceFullName = strLink
.Update
End With
End If
End With
Next k

End With

Already answered in the vba.general group.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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