0

我正在尝试检索 PowerPoint 演示文稿中对象的源路径链接。

目前,我是使用 FilePath = "C:\source file.xlsx" 手动输入excel表格的源文件路径。

有什么方法可以检测路径并将其存储为字符串,而无需对路径进行硬编码或要求用户输入它?

4

3 回答 3

1

我使用形状后面的源来获取链接对象的源:Shape.LinkFormat.SourceFullName

示例以下代码以获取链接对象背后的源代码:

Dim sld As PowerPoint.Slide, shp As PowerPoint.Shape, pres As PowerPoint.Presentation

For Each sld In pres.Slides
sld.Select
For Each shp In sld.Shapes
    If shp.Type = msoLinkedOLEObject Then
        ' do something with shp.LinkFormat.SourceFullName

    End If
Next

下一个

于 2018-09-24T14:35:14.913 回答
0

请参阅:
- Presentation.Name 属性
- Presentation.Path 属性

例如:

Sub demo()
    Dim ppPath As String, ppName As String
    ppPath = ActivePresentation.Path
    ppName = ActivePresentation.Name
    If ppPath = "" Then
        MsgBox "File not saved"
    Else
        MsgBox ppName & vbLf & "saved as" & vbLf & ppPath
    End If
End Sub
于 2018-09-24T23:34:35.973 回答
0

解决了。这是代码:

Dim pptSlide As Slide
Dim pptShape As PowerPoint.Shape

For Each pptSlide in pptPresentation.Slides
    For Each pptShape in pptSlide.Shapes
       If pptShape.Type = msoLinkedPicture Or pptShape.Type = msoLinkedOLEObject Then
           Path = pptShape.LinkFormat.SourceFullName
           Position = InStr(1, Path, "!", vbTextCompare)
           FileName = Left(Path, Position - 1)
       End If
   Next pptShape
Next pptSlide

路径检索对象的整个链接(包括图表编号和工作表名称),位置检测!在路径中(之后工作表名称开始)。FileName 然后考虑第一个 ! 左侧的字符,并将文件名存储为字符串。

于 2018-09-25T04:15:28.850 回答