繁体   English   中英

与Excel链接的Power Point表-如何更改源(VBA)?

[英]Power point tables linked to excel - How to change source (VBA)?

  1. 我有个大型演示文稿(约300张幻灯片),我需要制作几个版本,每个版本都连接到不同的excel文件。 我有一些代码可以更改预设站内所有形状的链接。 这对于图表来说都很好,但是链接表存在问题。 源更改是正确的,但是在此更改范围内存在表格无效(为第一个工作表单元格A1设置了范围)。 有没有办法保持范围不变?
  2. 另一个问题:更改图表源非常快(<1s),而更改链接表源需要一些时间(〜15s)。 如果有很多表,这将成为一个问题。 当我一次运行几次〜50张幻灯片时,代码运行得很好(大约5-10分钟),但是当我尝试在所有〜300张幻灯片上运行代码时,我等待了30分钟,但结果没有完成(没有暗恋,它看起来像过程冻结)。 我真的很好奇为什么会出现此问题。

我用于链接更改的下方代码:

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返回什么? 通常,不仅是文件名,而且还有指示链接指向的工作表和工作表范围内的其他代码。 您似乎正在将其更改为仅替换Excel文件的名称。

而是尝试使用“替换”将新的Excel文件的名称替换为.SourceFullName中的旧Excel文件的名称。 这将使其余的链接文本保持不变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM