【发布时间】:2016-05-27 22:34:26
【问题描述】:
我在将 Excel 文件链接到 Powerpoint 演示文稿时遇到问题。 Excel 文件托管在外部服务器上,该服务器分配给公司所有 PC 上的驱动器号。问题是 Excel 文件的链接会随机更改到它在外部服务器上的位置。
我在宏中放置了一个解决方法:
Global fso As New FileSystemObject
Public Sub MaakKoppelingenRelatief()
Dim i As Integer
Dim sld As Slide, shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Type = 3 Then
Dim path As String, fname As String
path = shp.LinkFormat.SourceFullName
fname = GetFilenameFromPath(path)
shp.LinkFormat.SourceFullName = fname
i = i + 1
End If
Next
Next
If i > 0 Then
MsgBox "Changed: " & CStr(i) & " Links", vbOK
Else
MsgBox "Couldn't find a linked file.", vbOK
End If
End Sub
Function GetFilenameFromPath(ByVal strPath As String) As String
Dim text1 As String
text1 = "N:\"
If Right$(strPath, 13) <> "\\tsclient\N\" And Len(strPath) > 0 Then
GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
End If
If Left$(strPath, 3) <> text1 And Len(strPath) > 0 Then
GetFilenameFromPath = text1 + strPath
End If
End Function
我遇到的问题在于这段代码:
If Left$(strPath, 3) <> text1 And Len(strPath) > 0 Then
GetFilenameFromPath = text1 + strPath
End If
它会不断将 text1 添加到我的路径中,而只有当 text1 当前不在路径的前 3 个字符中时才应该这样做。
谁能帮我弄清楚我做错了什么?
提前致谢!
【问题讨论】:
-
你传递的 strpath 的值是多少?如果前 3 个字符与 text1 不同,会发生什么?
-
strPath是链接的Excel文件的路径,如果前3个字符不一样应该加N:/
-
你能举一些例子来说明到底发生了什么吗?
标签: vba excel powerpoint