S
Simon Cleal
Changing the Excel source for an embedded chart - Word 2002
Hi,
I have a word document with numerous links to individual cells, ranges and
charts in an Excel sheet.
I'm trying to change the links programmatically so that all Excel objects
will point to a different spreadsheet.
I've written the code below to do this :
Public Sub ChangeSource
Dim intCount As Long
Dim strNewLink As String
strNewLink = "\\bwci-server-1\svr\_Template\ValnTemplate_CI_Test.XLS"
With ActiveDocument
' Loop through all the fields in document.
For intCount = 1 To .Fields.Count
With .Fields(intCount)
' If the field's type is an excel link then...
If .Type = 56 Then
With .LinkFormat
' change the source to the new source
.SourceFullName = strNewLink
End With
End If
End With
Next intCount
End With
End Sub
The code works fine for individual cells or ranges of cells but falls over
on the charts with error 6083 "Objects in this document contain links to
files that cannot be found. The linked information will not be updated."
This seems to be connected with the way Word writes the field code for a
linked chart as opposed to a linked cell
The linked cell field code has only one reference to the filename eg. {
LINK Excel.Sheet.8 "\\\\bwci-server-1\\SVR\\_Template\\ValnTemplate_CI.XLS"
"MemChngeData!R8C3" \a \t }
Whereas the linked Chart field code has 2 eg. { LINK Excel.Sheet.8
"\\\\bwci-server-1\\SVR\\_Template\\ValnTemplate_CI.XLS"
"MemChngeGraph![ValnTemplate_CI.XLS]MemChngeGraph Chart 3" \a \p }
I suspect that my code is changing the first occurrence of the filename but
not the second for the charts.
I’d like to know 2 things:
1) What is the property or code that I need, to change the links for charts?
2) How do I detect that I’m looking at a chart and not cells (as they both
seem to have the same type - 56)?
Thanks for your help
Simon
Hi,
I have a word document with numerous links to individual cells, ranges and
charts in an Excel sheet.
I'm trying to change the links programmatically so that all Excel objects
will point to a different spreadsheet.
I've written the code below to do this :
Public Sub ChangeSource
Dim intCount As Long
Dim strNewLink As String
strNewLink = "\\bwci-server-1\svr\_Template\ValnTemplate_CI_Test.XLS"
With ActiveDocument
' Loop through all the fields in document.
For intCount = 1 To .Fields.Count
With .Fields(intCount)
' If the field's type is an excel link then...
If .Type = 56 Then
With .LinkFormat
' change the source to the new source
.SourceFullName = strNewLink
End With
End If
End With
Next intCount
End With
End Sub
The code works fine for individual cells or ranges of cells but falls over
on the charts with error 6083 "Objects in this document contain links to
files that cannot be found. The linked information will not be updated."
This seems to be connected with the way Word writes the field code for a
linked chart as opposed to a linked cell
The linked cell field code has only one reference to the filename eg. {
LINK Excel.Sheet.8 "\\\\bwci-server-1\\SVR\\_Template\\ValnTemplate_CI.XLS"
"MemChngeData!R8C3" \a \t }
Whereas the linked Chart field code has 2 eg. { LINK Excel.Sheet.8
"\\\\bwci-server-1\\SVR\\_Template\\ValnTemplate_CI.XLS"
"MemChngeGraph![ValnTemplate_CI.XLS]MemChngeGraph Chart 3" \a \p }
I suspect that my code is changing the first occurrence of the filename but
not the second for the charts.
I’d like to know 2 things:
1) What is the property or code that I need, to change the links for charts?
2) How do I detect that I’m looking at a chart and not cells (as they both
seem to have the same type - 56)?
Thanks for your help
Simon