VBA用于在Excel中将文件从一个Sharepoint文件夹移动到另一个Sharepoint文件夹

VBA用于在Excel中将文件从一个Sharepoint文件夹移动到另一个Sharepoint文件夹,excel,vba,sharepoint,Excel,Vba,Sharepoint,我想写(或找到)一些VBA代码,当有人单击宏按钮时,基本上可以将XL工作表从一个Sharepoint文件夹移动到另一个Sharepoint文件夹 到目前为止,我找到的唯一解决方案是,我需要将Sharepoint链接映射到本地文件夹,然后使用.FSO代码,但这对我不起作用,因为出于安全原因,没有管理员访问权限 到目前为止,我发现的唯一代码如下 Function ConvertPath(path) As String ConvertPath = Replace(path, " ", "%20")

我想写(或找到)一些VBA代码,当有人单击宏按钮时,基本上可以将XL工作表从一个Sharepoint文件夹移动到另一个Sharepoint文件夹

到目前为止,我找到的唯一解决方案是,我需要将Sharepoint链接映射到本地文件夹,然后使用.FSO代码,但这对我不起作用,因为出于安全原因,没有管理员访问权限

到目前为止,我发现的唯一代码如下

Function ConvertPath(path) As String
  ConvertPath = Replace(path, " ", "%20")
  ConvertPath = Replace(ConvertPath, "/", "\")
  ConvertPath = Replace(ConvertPath, "http:", "")
End Function
Private Sub Approve_Click()
  Dim sDocPath As String
  Dim sDocPathConv As String
  Dim sFileName As String
  Dim sTargetPath As String
  Dim sSourcePath As String
  Dim fso As FileSystemObject
  Set fso = New FileSystemObject ' CreateObject("Scripting.FileSystemObject")
  sDocPath = ThisWorkbook.path
  sFileName = "WorkBook.xlsx"

  sDocPathConv = ConvertPath(sDocPath)

  sSourcePath = sDocPathConv & "https://xxxx.sharepoint.com/sites/xxxxxx/" & sFileName
  Debug.Print "Source: " & sSourcePath     
  sTargetPath = sDocPathConv & "https://xxxx.sharepoint.com/sites/xxxxxxx/" & sFileName
  Debug.Print "Target: " & sTargetPath
  fso.CopyFile sSourcePath, sTargetPath, True
End Sub

甚至这段代码也不起作用,因为它总是给出一个错误,上面写着“找不到路径”。我对VBA编程一点也不熟悉。

尝试在Windows资源管理器中将SharePoint同步到OneDrive。那么下面的代码应该可以工作了

还需要参考:Microsoft脚本运行时

作为字符串的公共函数strDisplayID() strDisplayID=Environ(“用户名”) 端函数

专用子命令按钮_单击()


End Sub

您能更好地解释一下“这对我不起作用,因为出于安全原因,没有管理员访问权限”是什么意思吗?您是否具有对共享文件夹的读写访问权限?是否可以手动将文件从一个共享文件夹复制到另一个共享文件夹?
sTargetPath=sDriveLetter“\https:\\xxxxxxxxxxxxxxxx\”&sFileName
是一个找不到的路径。请尝试
sTargetPath=sDriveLetter&“\https:\\xxxxxxxxxxxxxxxxxxxx\”&sFileName
Hi FaneDuru,感谢您的观看。是的,我可以在sharepoint中手动将文件从一个文件夹复制到另一个文件夹,但当我尝试映射网络驱动器的同一文件夹链接时,它不允许我执行soHi@Variatus,目前它在代码´´´´´´´´´´´sDocPath=ConvertPath(sDocPath)``中给我编译错误,它说Sub或Fun未定义。你能帮忙吗?请试试,地图的方式。。。
Dim fso As Object
Dim fileLocation As String

Set fso = CreateObject("Scripting.FileSystemObject")

fileLocation = "C:\Users\" & strDisplayID & "\YourPath\YourFile".pdf"
fso.MoveFile fileLocation