PDA

View Full Version : How can I programmatically relink my linked Excel worksheets in MS Word?



OliMouse
07-31-2007, 12:23 PM
I created a Microsoft Word document that contains dozens of linked Excel worksheets. I am searching for a method to programmatically search and replace all these links.

In searching online, I found code to perform this task for both Access and PPT ... but not for MS Word. :dunno

Here are the solutions I discovered for Access and PPT, available on the Microsoft website:

Access: "ACC2000: How to Programmatically Link or Embed an Object on a Form (Article ID 209990)"

PowerPoint: "PPT2000: Sample Code to Change Source of Linked Excel Worksheet (Article ID 222708)"

If anyone has a solution for Word, I'd really appreciate it!

OliMouse
08-01-2007, 07:46 AM
In case it helps, someone gave me the following code as a starting point. Can someone please help me to finish it?

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 it as you wish:
'Code to modify strLink
.SourceFullName = strLink
.Update
End With
End If
End With
Next k
End With
--------------