我正在尝试在PowerPoint演示文稿中检索对象的源路径链接。
目前,我正在使用FilePath =“ C:\ source file.xlsx”手动输入excel工作表的源文件路径。
有什么方法可以检测路径并将其存储为字符串,而无需对路径进行硬编码或要求用户输入?
答案 0 :(得分: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
下一步
答案 1 :(得分:0)
请参阅:
-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
答案 2 :(得分: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认为第一个!左边的字符,并将文件名存储为字符串。