office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請(qǐng)用微信掃碼)

        

VBA使用FileSystemObject復(fù)制或移動(dòng)文件

2017-08-08 16:50:00
zstmtony
原創(chuàng)
7967

以下VBA代碼 使用FileSystemObject復(fù)制或移動(dòng)文件,適用于access excel等VBA環(huán)境



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"  '目標(biāo)路徑
    Set objFS = CreateObject("Scripting.FileSystemObject")  '創(chuàng)建FileSystemObject fso對(duì)象
    With objFS
        If .FileExists(strDestination) Then
            .DeleteFile (strDestination)   ‘如果目標(biāo)文件存在,先刪除目標(biāo)文件
        End If
        .MoveFile strSource, strDestination   '移動(dòng)文件
    End With
    Set objFS = Nothing
End Sub
分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動(dòng)訪問