簡體   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