excel - PowerPoint 链接对象的新驱动器映射 - VBA 解决方案

标签 excel vba powerpoint

PowerPoint 中的所有链接对象(链接到 excel)不再被识别,因为 IT 已将服务器迁移到新路径并关闭旧路径。

我曾尝试使用 (https://exceloffthegrid.com/edit-links-in-powerpoint-using-vba/) 下面的宏,但由于旧服务器不再运行,当宏尝试打开旧文件路径时,它会出错

有替代解决方案吗?

Sub EditPowerPointLinks()

Dim oldFilePath As String
Dim newFilePath As String
Dim pptPresentation As Presentation
Dim pptSlide As Slide
Dim pptShape As Shape

'The old file path as a string (the text to be replaced)
oldFilePath = "String of\File Path\To Be Replaced\Excel File.xlsx"

'The new file path as a string (the text to replace with)
newFilePath = "String of\New File Path\Excel File 2.xlsx"

'Set the variable to the PowerPoint Presentation
Set pptPresentation = ActivePresentation

'Loop through each slide in the presentation
For Each pptSlide In pptPresentation.Slides

    'Loop through each shape in each slide
    For Each pptShape In pptSlide.Shapes

        'Find out if the shape is a linked object or a linked picture
        If pptShape.Type = msoLinkedPicture Or pptShape.Type _ 
        = msoLinkedOLEObject Then

            'Use Replace to change the oldFilePath to the newFilePath
            pptShape.LinkFormat.SourceFullName = Replace(LCase _
            (pptShape.LinkFormat.SourceFullName), LCase(oldFilePath), newFilePath)

        End If
    Next
Next

'Update the links
pptPresentation.UpdateLinks


End Sub

最佳答案

你的代码没问题,我也测试过。

新链接的设置由应用程序处理不同:

  • 如果你设置一个新的SourceFullName链接图片(Shape.Type = msoLinkedPicture),
    应用程序接受任何链接,并且代码不会引发错误。
  • 如果您尝试设置新的SourceFullName对于链接的 OLE 对象 (Shape.Type = msoLinkedOLEObject),应用程序会立即测试新文件是否真的存在。
    如果链接的 OLE 对象不存在,您将收到错误消息。

  • 结果:您必须确保新路径指向现有文件(并且您需要适当的访问权限)。

    关于excel - PowerPoint 链接对象的新驱动器映射 - VBA 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56627694/

    相关文章:

    java - 如何使用 Java 在 Selenium Webdriver 中通过标题名称而不是索引/键来引用 Excel 列?

    excel - 在 VBA 中使用字典会给我的代码带来任何缺陷吗?

    excel - VBA Excel 比较两个列表是否匹配,在单独的工作表上输出结果

    vba搜索功能

    vba - 如何从关闭的工作簿中的特定单元格读取信息,然后使用 Microsoft Excel 中的 VBA 将其粘贴到事件工作表的单元格中?

    java - Apache POI Powerpoint 替代方案

    vba - 出错时继续下一步不起作用

    excel - VBA Range.Rows.Count 给出了意想不到的结果

    c# - 如何在 EPPlus 中使用 C# 删除 AutoFilter

    c# - 使用 OpenXML 合并 PowerPoint 幻灯片