-1
すべてのExcelファイルをあるフォルダパスから別のフォルダパスに移動しようとしましたが、アクセス権が拒否されました。ここに私のコードだ:ランタイムエラー70ファイルを別のフォルダに移動する際のアクセス許可が拒否されました
Sub Move_Certain_Files_To_New_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
FromPath = "R:\FromPath\Files" '<< Change
ToPath = "R:\ToPath\Backup" & Format(Now, "yyyy-mm-dd h-mm-ss")
FileExt = "*.xl*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CreateFolder (ToPath)
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
End Sub
エラーは、この部分からです:FSO.MoveFile出典:= FromPath & FileExt、デスティネーション:= ToPath 任意の助けに感謝します! :)
現在開いているファイルを移動していますか? – user3598756
いいえ、ファイルは開かれません。 – Meedee
MoveFileでワイルドカードを使用することはできません。例:http://stackoverflow.com/questions/20905889/vbscript-to-move-file-with-wildcard-if-it-exists –