链接到 excel 的电源点表格 - 如何更改来源 (VBA)?
Power point tables linked to excel - How to change source (VBA)?
- 我有很多演示文稿(~300 张幻灯片),我需要制作几个版本,每个版本都连接到不同的 excel 文件。我有代码可以更改 prestations 内所有形状的 links。对于图表来说一切都很好,但是 linked tables 有问题。来源更改是正确的,但在此更改范围内 table 不一致(范围设置为第一个 sheet 单元格 A1)。
有没有办法保持范围不变?
- 附加问题:更改图表源非常快 (<1s),而更改 linked table 源需要一些时间 (~15s)。如果 table 很多,这就会成为一个问题。
当我 运行 在一张 运行 中编码几次 ~50 张幻灯片时,它进行得很顺利(花了 ~5-10 分钟),但是当我在所有 ~300 张幻灯片上尝试 运行 它时,我等了 30 分钟而且它没有完成(没有迷恋,看起来程序冻结了)。很好奇为什么会出现这个问题
以下我用于 link 更改的代码:
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
欢迎所有提示! :)
你看过什么 .SourceFullName returns 了吗?通常它不仅仅是文件名,还有进一步的代码指示 sheet 和 sheet 中的范围 link 指向的内容。看起来您只是将其更改为替换 Excel 文件的名称。
相反,请尝试使用 Replace 将新 Excel 文件的名称替换为 .SourceFullName 中旧 Excel 文件的名称。这将使 link 文本的其余部分保持不变。
- 我有很多演示文稿(~300 张幻灯片),我需要制作几个版本,每个版本都连接到不同的 excel 文件。我有代码可以更改 prestations 内所有形状的 links。对于图表来说一切都很好,但是 linked tables 有问题。来源更改是正确的,但在此更改范围内 table 不一致(范围设置为第一个 sheet 单元格 A1)。 有没有办法保持范围不变?
- 附加问题:更改图表源非常快 (<1s),而更改 linked table 源需要一些时间 (~15s)。如果 table 很多,这就会成为一个问题。 当我 运行 在一张 运行 中编码几次 ~50 张幻灯片时,它进行得很顺利(花了 ~5-10 分钟),但是当我在所有 ~300 张幻灯片上尝试 运行 它时,我等了 30 分钟而且它没有完成(没有迷恋,看起来程序冻结了)。很好奇为什么会出现这个问题
以下我用于 link 更改的代码:
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
欢迎所有提示! :)
你看过什么 .SourceFullName returns 了吗?通常它不仅仅是文件名,还有进一步的代码指示 sheet 和 sheet 中的范围 link 指向的内容。看起来您只是将其更改为替换 Excel 文件的名称。
相反,请尝试使用 Replace 将新 Excel 文件的名称替换为 .SourceFullName 中旧 Excel 文件的名称。这将使 link 文本的其余部分保持不变。