简体   繁体   English

如何将文件从一个 SharePoint 文件夹移动到另一个文件夹

[英]How to move a file from one SharePoint folder to another

I need to move a file from one SharePoint folder to another folder after I click the approve button.单击批准按钮后,我需要将文件从一个 SharePoint 文件夹移动到另一个文件夹。

I am getting the error:我收到错误:

"user defined type not defined"
Private Sub Approve_Click()
  Dim sDocPath As String
  Dim sFileName As String
  Dim sTargetPath As String
  Dim sSourcePath As String
  Dim sDriveLetter As String
  Dim fso As FileSystemObject
  Dim net As WshNetwork

  sDriveLetter = "S:"
  sFileName = "WorkBook.xlsm"

  Set fso = New FileSystemObject & CreateObject("Scripting.FileSystemObject")
  sDocPath = ThisWorkbook.path
  ‘sDocPath = ConvertPath(sDocPath)

  Set net = New WshNetwork & CreateObject("WScript.Network")
  Debug.Print "Path to map: " & sDocPath
  net.MapNetworkDrive sDriveLetter, sDocPath

  sSourcePath = sDriveLetter & "\https:\\xxxxxOrder%20Form\" & sFileName
  Debug.Print "Source: " & sSourcePath

  sTargetPath = sDriveLetter "\https:\\xxxxxxxxxxxxxxxxxxx\" & sFileName
  Debug.Print "Target: " & sTargetPath

  fso.CopyFile sSourcePath, sTargetPath, True

  net.RemoveNetworkDrive sDriveLetter

  Set net = Nothing
  Set fso = Nothing

End Sub

You either need to add the reference "Microsoft Scripting Runtime" :您要么需要添加引用“Microsoft Scripting Runtime”

VBA Editor › Tools › References VBA 编辑器 › 工具 › 参考在此处输入图片说明
More info see: https://trumpexcel.com/vba-filesystemobject/更多信息请参见: https : //trumpexcel.com/vba-filesystemobject/

This method is called early binding and you can use it like below (inkluding intelli sense):这种方法称为早期绑定,您可以像下面这样使用它(包括智能感知):

Dim fso As FileSystemObject
Set fso = New FileSystemObject 

Or you use late binding (without setting the reference) and without intelli sense then you need to use the code like below:或者您使用后期绑定(不设置引用)并且没有智能感知,那么您需要使用如下代码:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

but whit you did looks somehow like a mixture of both which cannot work:但是你所做的看起来有点像两者的混合物,无法工作:

Set fso = New FileSystemObject & CreateObject("Scripting.FileSystemObject")

Same for Set net = New WshNetwork & CreateObject("WScript.Network") wich must either use the reference "Windows Script Host Object Model" and:Set net = New WshNetwork & CreateObject("WScript.Network")必须使用参考“Windows Script Host Object Model”和:

Dim net As WshNetwork
Set net = New WshNetwork

or late binding and:或后期绑定和:

Dim net As Object
Set net = CreateObject("WScript.Network")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于在 Excel 中将文件从一个 Sharepoint 文件夹移动到另一个文件夹的 VBA - VBA for moving file from one Sharepoint folder to another in Excel 将文件从一个文件夹移动到另一个文件夹 - 错误 53 找不到文件 - Move file from one folder to another - Error 53 File not Found VBA遍历表并将文件从一个文件夹移动到另一个 - VBA to iterate through table and move file from one folder to another 如何在有条件的情况下将工作簿从一个文件夹移动到另一个文件夹? - How to move Workbooks from one folder to another with conditions? 将文件从一个文件夹移动到另一个文件夹 - move files from one folder to another 如何根据 Excel 中的列表将文件夹从一个文件夹复制或移动到另一个文件夹? - How To Copy Or Move Folders From One Folder To Another Based On A List In Excel? 根据 excel 中的列表将文件夹从一个位置移动到另一个位置 - move folder from one location to another based on list in excel 使用 VBA 将文件从一个文件夹移动到另一个文件夹 - to move files from one folder to another using VBA 如何将元素从一帧移动到另一帧 - How to move a element from one frame to another 仅将文件名匹配的文件从一个文件夹移动到另一个文件夹 - Move only files with matching files names from one folder to another folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM