PPT 更改路径文件链接 excel 文件与 VBA
PPT change pathfile linked excel file with VBA
我有一个关于 linked Excel 文件到 Powerpoint 演示文稿的问题。
Excel 文件托管在外部服务器上,该服务器分配给公司所有 PC 上的驱动器号。问题是 link 到 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 个字符中时才应该这样做。
谁能帮我弄清楚我做错了什么?
提前致谢!
VBA 中的文本比较有时有点让人恼火。而不是使用
if Left$(strPath, 3) <> text1
试试这个:
If StrComp(Left$(StrPath,3),text1) <> 0
如果这不起作用,试试这个:
If InStr(1,Left$(StrPath,3),text1) = 0
我有一个关于 linked Excel 文件到 Powerpoint 演示文稿的问题。 Excel 文件托管在外部服务器上,该服务器分配给公司所有 PC 上的驱动器号。问题是 link 到 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 个字符中时才应该这样做。
谁能帮我弄清楚我做错了什么?
提前致谢!
VBA 中的文本比较有时有点让人恼火。而不是使用
if Left$(strPath, 3) <> text1
试试这个:
If StrComp(Left$(StrPath,3),text1) <> 0
如果这不起作用,试试这个:
If InStr(1,Left$(StrPath,3),text1) = 0