excel - 我的代码无法将文件从 1 个文件夹移动到另一个文件夹
问题描述
我尝试了 2 个不同的代码将文件从 Sharepoint 中的 1 个文件夹移动到另一个文件夹,但收到 2 个不同的错误。请帮忙看看我做错了什么。
错误:运行时错误 5 - 无效的过程调用或参数
Sub MoveAFile()
'Move file to archive after download complete
Dim ogfilepath, newfilepath As String
Dim i As Double
i = 11
Do
ogfilepath = Worksheets(CN.Name).Cells(i, 2).Value 'https://wwpcis.sharepoint.com/sites/XXX/filename.pdf
newfilepath = Worksheets(CN.Name).Cells(i, 5).Value
'https://wwpcis.sharepoint.com/sites/XXX/YYY/filename.pdf
Name ogfilepath As _
newfilepath
i = i + 1
Loop Until Cells(i, 1).Value = ""
MsgBox ("Moved to archive")
End Sub
错误:运行时错误 76 找不到路径
Sub FSOMoveAllFiles()
'test new code for moving files
Dim FSO As New FileSystemObject
Dim FromPath As String
Dim ToPath As String
Dim FileInFromFolder As Object
FromPath = https://wwpcis.sharepoint.com/sites/XXX/filename.pdf
ToPath = https://wwpcis.sharepoint.com/sites/XXX/YYY/filename.pdf
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each FileInFromFolder In FSO.GetFolder(FromPath).Files
FileInFromFolder.Move ToPath
Next FileInFromFolder
End Sub
解决方案
推荐阅读
- delphi - Graphics.Polygon 代码不起作用 - 我错过了什么?
- python - Python BeautifulSoup 没有输出
- docker - /etc/rc* 未在 Docker 中的 Ubuntu 18.04 上运行。启动时无法启动 cron
- android - 在 API 19 及更低版本中向 Spinners 添加边距不起作用
- c# - 如何逐行、部分地从文本文件中取出数据?
- c++ - 了解当传递给函数时 shared_ptr 引用计数何时增加
- swift - 在 `UITableviewcell` 中包装 `View` 遇到麻烦
- r - 无法使用 include_graphics 在 Rmarkdown 中插入 png(错误:文件不是 PNG 格式)
- python - 对多个值使用 and 操作
- python - “scoped_session”对象没有属性“create_all”“scoped_session”对象没有属性“session”