office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

VBA使用FileSystemObject复制或移动文件

2017-08-08 16:50:00
zstmtony
原创
7460

以下VBA代码 使用FileSystemObject复制或移动文件,适用于access excel等VBA环境



Public Sub Move_File()
    Dim strSource As Variant
    Dim strDestination As String
    Dim objFS As Object
    
    strSource = "C:\Temp_C\Test.txt"  '源路径
    strDestination = "C:\Temp_Test\Test.txt"  '目标路径
    Set objFS = CreateObject("Scripting.FileSystemObject")  '创建FileSystemObject fso对象
    With objFS
        If .FileExists(strDestination) Then
            .DeleteFile (strDestination)   ‘如果目标文件存在,先删除目标文件
        End If
        .MoveFile strSource, strDestination   '移动文件
    End With
    Set objFS = Nothing
End Sub
分享