简体   繁体   English

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

[英]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.

相关问题 VBA从共享点文件夹中打开特定的Excel文件 - VBA to open a particular excel file from an sharepoint folder 将行从一个表移动到另一个(Excel VBA) - Moving Rows from One Table to Another (Excel VBA) excel vba - 将文件从一个文件夹复制到另一个文件夹,但如果文件存在不覆盖? - excel vba - copy file from one folder to another but if file exists do not overwrite? 使用 Excel VBA 将文件从一个文件夹复制到另一个文件夹的更快方法 - Faster Way to copy files from one folder to another with Excel VBA 如何将文件从一个 SharePoint 文件夹移动到另一个文件夹 - How to move a file from one SharePoint folder to another Excel vba:将文件从一个文件夹同时复制到多个文件夹 - Excel vba: copy file from one folder to many folders simultaneously VBA遍历表并将文件从一个文件夹移动到另一个 - VBA to iterate through table and move file from one folder to another 从Sharepoint文件夹访问Excel文件 - To access an Excel file from a Sharepoint Folder Excel VBA脚本,用于将数据从一张纸移动到另一张纸,而不会覆盖编译错误。 - Excel VBA Script for moving data from one sheet to another without overwriting compile errors. Excel VBA [仅] 将行值从一张工作表移动到另一张工作表 - 当前代码正在运行,只需要调整 - Excel VBA Moving Row Values [Only] from one Sheet to another - Current code is working, just needs tweaking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM