检索 PPT 对象的名称 link - VBA
Retrieve name of PPT object link - VBA
我正在尝试检索 PowerPoint 演示文稿中对象的源路径 link。
目前我是手动输入excel sheet的源文件路径using FilePath = "C:\source file.xlsx".
有什么方法可以检测路径并将其存储为字符串,而无需对路径进行硬编码或要求用户输入?
我使用形状后面的源来获取链接对象的源: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
下一个
参见:
- Presentation.Name Property
- Presentation.Path Property
例如:
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
解决了。这是代码:
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
Path 检索整个 link 对象(包括图表编号和工作表名称),Position 检测 ! 的位置在路径中(工作表名称开始后)。 FileName 然后考虑第一个 ! 左边的字符,并将文件名存储为字符串。
我正在尝试检索 PowerPoint 演示文稿中对象的源路径 link。
目前我是手动输入excel sheet的源文件路径using FilePath = "C:\source file.xlsx".
有什么方法可以检测路径并将其存储为字符串,而无需对路径进行硬编码或要求用户输入?
我使用形状后面的源来获取链接对象的源: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
下一个
参见:
- Presentation.Name Property
- Presentation.Path Property
例如:
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
解决了。这是代码:
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
Path 检索整个 link 对象(包括图表编号和工作表名称),Position 检测 ! 的位置在路径中(工作表名称开始后)。 FileName 然后考虑第一个 ! 左边的字符,并将文件名存储为字符串。