[英]VBA for moving file from one Sharepoint folder to another in Excel
I want to write (or find) some VBA code that basically moves an XL sheet from one Sharepoint folder to another Sharepoint folder when someone clicks on the macro button.我想编写(或找到)一些 VBA 代码,当有人单击宏按钮时,这些代码基本上会将 XL 工作表从一个 Sharepoint 文件夹移动到另一个 Sharepoint 文件夹。
The only solution that I found until now is that I need to map the Sharepoint link into local folder and then use .FSO code but this isn't working for me since there is no administrator access to do that for security reasons.到目前为止,我发现的唯一解决方案是我需要将 Sharepoint 链接映射到本地文件夹,然后使用 .FSO 代码,但这对我不起作用,因为出于安全原因没有管理员访问权限。
The only code which I found out until now is below到目前为止我发现的唯一代码如下
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
And even this code is not working as it always gives an error which says "Path not found".甚至这段代码也不起作用,因为它总是给出一个错误,指出“找不到路径”。 I am not at all familiar with VBA programming.
我一点也不熟悉 VBA 编程。
Try syncing the SharePoint to OneDrive in Windows Explorer.尝试在 Windows 资源管理器中将 SharePoint 同步到 OneDrive。 Then code below should work.
那么下面的代码应该可以工作。
Will also need Reference: Microsoft Scripting Runtime还需要参考:Microsoft Scripting Runtime
Public Function strDisplayID() As String
strDisplayID = Environ("USERNAME")
End Function
Private Sub CommandButton_Click()
Dim fso As Object
Dim fileLocation As String
Set fso = CreateObject("Scripting.FileSystemObject")
fileLocation = "C:\Users\" & strDisplayID & "\YourPath\YourFile".pdf"
fso.MoveFile fileLocation
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.