简体   繁体   English

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

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

  1. I have big presentation (~300 slides) And i need to make few versions of it, each connected to diffrent excel file. 我有个大型演示文稿(约300张幻灯片),我需要制作几个版本,每个版本都连接到不同的excel文件。 I have code that changes links for all shapes inside prestations. 我有一些代码可以更改预设站内所有形状的链接。 Its all good for charts, but there is problem with linked tables. 这对于图表来说都很好,但是链接表存在问题。 Source change is correct, but during this change range for table dissapires (range is set for 1st sheet cell A1). 源更改是正确的,但是在此更改范围内存在表格无效(为第一个工作表单元格A1设置了范围)。 Is there way to keep the range unchanged? 有没有办法保持范围不变?
  2. Additional question: changing chart source is very fast (<1s),whereas changing linked table source takes some time (~15s). 另一个问题:更改图表源非常快(<1s),而更改链接表源需要一些时间(〜15s)。 This becomes a problem where there is a lot tables. 如果有很多表,这将成为一个问题。 When i run code few times ~50 slides in one run it went well (took ~5-10min), but when i tried run it on all ~300 slides i waited for 30min and it didn't finish (there was no crush, it looked like procedure frozed). 当我一次运行几次〜50张幻灯片时,代码运行得很好(大约5-10分钟),但是当我尝试在所有〜300张幻灯片上运行代码时,我等待了30分钟,但结果没有完成(没有暗恋,它看起来像过程冻结)。 Im really curious why this problem occures. 我真的很好奇为什么会出现此问题。

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.

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