[英]Change CHART source link in Word VBA
我有一個單詞文檔,其中的表格和圖表鏈接到excel。 我需要每月更改一次這些鏈接。 當我運行下面的鏈接時,表源更改為新文件,但圖表的源鏈接保持不變,並且未更改。 這里的代碼:
Sub Replace_Link()
Dim fieldCount As Integer, x As Long
With ActiveDocument
fieldCount = .Fields.Count
For x = 1 To fieldCount
With .Fields(x)
Debug.Print .LinkFormat.SourceFullName;
.LinkFormat.SourceFullName = "Q:\LINKNEWFILE"
.Update
.LinkFormat.AutoUpdate = False
DoEvents
End With
Next x
End With
End Sub
誰能幫我嗎?
謝謝
嘗試將表格和圖表處理為形狀和內嵌形狀:
Sub Replace_Links()
Dim x As Long: Const StrLnk As String = "Q:\LINKNEWFILE"
With ActiveDocument
For x = .Shapes.Count To 1 Step -1
With .Shapes(x)
If Not .LinkFormat Is Nothing Then
With .LinkFormat
.SourceFullName = StrLnk
.Update
.AutoUpdate = False
End With
End If
End With
Next x
For x = .InlineShapes.Count To 1 Step -1
With .InlineShapes(x)
If Not .LinkFormat Is Nothing Then
With .LinkFormat
.SourceFullName = StrLnk
.Update
.AutoUpdate = False
End With
End If
End With
Next x
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.