我爱帮助网--QQ交流群号

Nas交流与矿渣群(unraid 群晖 猫盘 蜗牛等):372167400         物联网/智能家居群:518812757             帮助教程:手册大全

软件使用与建站群:1057308983      虚拟化交流群:13448651

VBA移动文件及移动文件夹(目录)

2020-02-25 08:00:00
zstmtony
原创
2998

一、VBA移动文件



Public Sub VBA移动文件()
    Dim strFile As String
    Dim strPathNew As String
    Dim fso As Scripting.FileSystemObject
    strFile = ThisWorkbook.Path & "\测试文件.txt"    '准备移动的文件
    strPathNew = ThisWorkbook.Path & "\测试子目录\"    '移动的目标位置
    Set fso = New Scripting.FileSystemObject
    If fso.FileExists(strFile) Then  '判断是否存在
        fso.MoveFile strFile, strPathNew
        MsgBox "已经将文件 " & strFile & " 移到了文件夹 " & strPathNew
    Else
        MsgBox "要移动的文件不存在"
    End If
    Set fso = Nothing
End Sub



二、VBA移动文件夹

Public Sub VBA移动文件夹()
    Dim strFolder As String
    Dim strPathNew As String
    Dim fso As Scripting.FileSystemObject
    strFolder = ThisWorkbook.Path & "\待移动文件平"    '要准备移动的文件夹,要先创建这个目录 
    strPathNew = ThisWorkbook.Path & "\测试子目录\"    '移动的目标位置
    Set fso = New Scripting.FileSystemObject
    If fso.FolderExists(strFolder) Then  '判断是否存在
        fso.MoveFolder strFolder, strPathNew
        MsgBox "已经将文件夹 " & strFolder & " 移到了文件夹 " & strPathNew
    Else
        MsgBox "要移动的文件夹不存在"
    End If
    Set fso = Nothing
End Sub

0
发表评论
评论通过审核后显示。
文章分类
联系我们
联系人: 王先生