Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PPT更改路径文件用VBA链接excel文件_Vba_Excel_Powerpoint - Fatal编程技术网

PPT更改路径文件用VBA链接excel文件

PPT更改路径文件用VBA链接excel文件,vba,excel,powerpoint,Vba,Excel,Powerpoint,我在将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

我在将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
全局fso作为新的FileSystemObject
公共分包商Maakkoppelingenerelatief()
作为整数的Dim i
将sld调暗为滑块,shp调暗为形状
对于ActivePresentation.Slides中的每个sld
对于sld形状中的每个shp
如果shp.Type=3,则
Dim路径为字符串,fname为字符串
path=shp.LinkFormat.SourceFullName
fname=GetFilenameFromPath(路径)
shp.LinkFormat.SourceFullName=fname
i=i+1
如果结束
下一个
下一个
如果i>0,那么
MsgBox“已更改:”&CStr(i)和“链接”,vbOK
其他的
MsgBox“找不到链接文件”,vbOK
如果结束
端接头
函数GetFilenameFromPath(ByVal strPath作为字符串)作为字符串
Dim text1作为字符串
text1=“N:\”
如果右$(strPath,13)“\\t客户端\N\”和Len(strPath)>0,则
GetFilenameFromPath=GetFilenameFromPath(左$(strPath,Len(strPath)-1))+右$(strPath,1)
如果结束
如果左$(strPath,3)text1和Len(strPath)>0,则
GetFilenameFromPath=text1+strPath
如果结束
端函数
我遇到的问题是这段代码:

If Left$(strPath, 3) <> text1 And Len(strPath) > 0 Then
    GetFilenameFromPath = text1 + strPath
End If
如果左$(strPath,3)text1和Len(strPath)>0,则
GetFilenameFromPath=text1+strPath
如果结束
它不断地将text1添加到我的路径中,而只有当text1当前不在路径的前3个字符中时,它才应该这样做

有人能帮我找出我做错了什么吗


提前谢谢

VBA中的文本比较有时有点烦人。而不是使用

if Left$(strPath, 3) <> text1

VBA中的文本比较有时有点烦人。而不是使用

if Left$(strPath, 3) <> text1

您正在传递的strpath的值是多少?如果前3个字符与text1不相同,会发生什么情况?strPath是链接Excel文件的路径,如果前3个字符不相同,则应添加N:/N能否举例说明具体发生了什么情况?传递的strPath值是多少?如果前3个字符与text1不相同,该怎么办?strPath是链接Excel文件的路径,如果前3个字符不相同,则应添加N:/N您能举一些例子说明到底发生了什么吗?
If InStr(1,Left$(StrPath,3),text1) = 0