簡體   English   中英

如何將文件從一個 SharePoint 文件夾移動到另一個文件夾

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

單擊批准按鈕后,我需要將文件從一個 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

您要么需要添加引用“Microsoft Scripting Runtime”

VBA 編輯器 › 工具 › 參考在此處輸入圖片說明
更多信息請參見: https : //trumpexcel.com/vba-filesystemobject/

這種方法稱為早期綁定,您可以像下面這樣使用它(包括智能感知):

Dim fso As FileSystemObject
Set fso = New FileSystemObject 

或者您使用后期綁定(不設置引用)並且沒有智能感知,那么您需要使用如下代碼:

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

但是你所做的看起來有點像兩者的混合物,無法工作:

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

Set net = New WshNetwork & CreateObject("WScript.Network")必須使用參考“Windows Script Host Object Model”和:

Dim net As WshNetwork
Set net = New WshNetwork

或后期綁定和:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM