我在 VBA 编码方面遇到了麻烦。
我有一个 excel 文件,里面有各种带有数据和图表的工作表。这些图表链接到一个 Powerpoint(图表已被复制并粘贴为“带有链接”的对象)。
问题是,我现在有一个包含 130 多张幻灯片的巨大 Powerpoint,每张幻灯片上大约有 18 个图表……所以超过 2000 个图表。
我想更改我的工作表的名称并复制一些幻灯片以使用过滤后的数据填充图表。
我的问题: - 如果更改工作表名称,当然链接已损坏。使用 UI 手动更新所有内容是不可能的;- 在 PowerPoint 中复制幻灯片时,图形仍然链接到与原始幻灯片相同的 Excel 工作表 - 更改链接的唯一方法是删除所有图形,在 Excel 中复制工作表 - 填充新数据 - 复制粘贴再将每张图一一链接到 PowerPoint 中。
我曾尝试使用宏,但是...它更改了链接的整个地址,删除了所有工作表信息。有没有办法修改硬地址但保留相同的excel文件 - 只更改工作表?
这是我试图用表“100s”替换表“T3”的内容。宏运行没有错误,但所有对象都被我的 excel 文件中的整个“100s”工作表的副本替换:(
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 = "\\Server\01xxxx\xxx\xx\X 4.xlsx!T3"
'The new file path as a string (the text to replace with)
newFilePath = "\\Server\01xxxx\xxx\xx\X 4.xlsx!100s"
'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
有没有人知道如何仅更改工作表名称并保留所有对象名称?
非常感谢,亚瑟
事实上,该公式工作正常。链接的替换不起作用,因为在我复制的原始工作表中,选择窗格中的第一个对象是 Graph 3。复制工作表时,Excel 会自动尝试使其从 1 开始,因此 Graph 3 变成了 Graph 1。然后,替换链接时,图表不匹配。
要使此公式起作用,请确保在 Excel 的“选择窗格”中,您的图表在原始工作表和新工作表之间的命名方式相同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句