【VBA】Move file

You can move file!

PR

VBA Code

As an example, move the file.

file
file
Option Explicit

Sub sampleProc()
    
    Dim fso As Object
    Dim fileFullPath As String
    Dim folderPath As String
    
    'Set "File path you want to move"
    fileFullPath = "C:\Users\user\Desktop\hogehoge.txt"
    
    'Set "Folder path"
    folderPath = "C:\Users\user\Desktop\folder_001\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    'Move File
    Call fso.MoveFile(Source:=fileFullPath, Destination:=folderPath)
    
    Set fso = Nothing
    
End Sub

Set “File path you want to move”(Line 10).

Set “Folder path”(Line 13).

Move File(Line 18).

PR

Result

Yon moved file!

Result
Result
PR

FYI

For more information about following, see the following official online manual:

MoveFile method” of “FileSystemObject”

タイトルとURLをコピーしました