![](/img/trans.png)
[英]VBA for moving file from one Sharepoint folder to another in Excel
[英]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.