1
我有一個鏈接的Excel文件到Powerpoint演示文稿的問題。 Excel文件託管在外部服務器上,該服務器分配給公司所有PC上的盤符。問題在於Excel文件的鏈接將隨機更改爲它在外部服務器上的位置。PPT更改路徑文件鏈接excel文件與VBA
我把一個變通方案,宏:
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
它使添加文本1至我的道路,而只當text1當前不在路徑的前3個字符中時應該這樣做。
有人能幫我弄清楚我做錯了什麼嗎?
在此先感謝!
什麼是你逝去strPath的價值?如果前3個字符與text1不一樣,會發生什麼? – Spidey
strPath是鏈接的Excel文件的路徑,如果前3個字符不相同,它應該添加N:/ –
您可以舉一些例子來說明究竟發生了什麼? – Spidey