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

问题描述 投票:0回答:1

我需要在点击批准按钮后,将一个文件从一个SharePoint文件夹移动到另一个文件夹。

我收到了错误信息。

"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
excel vba sharepoint
1个回答
0
投票

您需要添加引用 "Microsoft Scripting Runtime":

VBA编辑器 ' 工具 ' 参考资料 enter image description here 更多信息请看。https:/trumpexcel.comvba-filesystemobject。

这个方法被称为 早订 你可以像下面一样使用它(inkluding intelli sense)。

Dim fso As FileSystemObject
Set fso = New FileSystemObject 

或者你用 迟装 (不设置引用),也没有intelli sense,那么你需要使用下面的代码。

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

但你的代码看起来就像是两者的混合体,无法使用。

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

同样的 Set net = New WshNetwork & CreateObject("WScript.Network") 必须使用参考文献 "Windows脚本主机对象模型" 和。

Dim net As WshNetwork
Set net = New WshNetwork

或后期装订和:

Dim net As Object
Set net = CreateObject("WScript.Network")
© www.soinside.com 2019 - 2024. All rights reserved.