[英]Power point tables linked to excel - How to change source (VBA)?
Belowe code i use for link change: 我用于链接更改的下方代码:
Sub UpdateLinks()
Dim ExcelFile
Dim exl As Object
Set exl = CreateObject("Excel.Application")
'Open a dialog box to promt for the new source file.
ExcelFile = exl.Application.GetOpenFilename(, , "Select Excel File")
Dim i As Integer
Dim k As Integer
'Go through every slide
For i = 1 To ActivePresentation.Slides.Count
With ActivePresentation.Slides(i)
'Go through every shape on every slide
For k = 1 To .Shapes.Count
'Turn of error checking s that it doesn 't crash if the current shape doesn't already have a link
On Error Resume Next
'Set the source to be the same as teh file chosen in the opening dialog box
.Shapes(k).LinkFormat.SourceFullName = ExcelFile
If .Shapes(k).LinkFormat.SourceFullName = ExcelFile Then
'If the change was successful then also set it to update automatically
.Shapes(k).LinkFormat.AutoUpdate = ppUpdateOptionAutomatic 'other option is ppUpdateOptionManual/ppUpdateOptionAutomatic
End If
On Error GoTo 0
Next k
End With
Next i
End Sub
All tips are welcome! 欢迎所有提示! :) :)
Have you looked at what .SourceFullName returns? 您是否看过.SourceFullName返回什么? Usually it's not just the file name but also further code that indicates what sheet and range within the sheet the link points to. 通常,不仅是文件名,而且还有指示链接指向的工作表和工作表范围内的其他代码。 It looks like you're changing that to just the name of the replacement Excel file. 您似乎正在将其更改为仅替换Excel文件的名称。
Instead, try using Replace to substitute the name of the new Excel file for the name of the old Excel file in .SourceFullName. 而是尝试使用“替换”将新的Excel文件的名称替换为.SourceFullName中的旧Excel文件的名称。 That'll leave the rest of the link text intact. 这将使其余的链接文本保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.