ray88’s diary

お仕事で困ったとき用の自分用の覚書

VBA ファイルとフォルダの移動

Sub MoveFile()
    'ファイルの移動
    Dim strBaseFilePath As String     '元のファイル格納先フォルダパス
    Dim strDstFilePath As String      '移動先のファイル格納フォルダパス
    Dim strTargetFileName As String   '移動対象ファイル名
        
    '各種フォルダとファイルのパス設定
    strBaseFilePath = "C:\Users\デスクトップ\ExcelVBAプロジェクト\元フォルダ"
    strDstFilePath = "C:\Users\デスクトップ\ExcelVBAプロジェクト\移動後フォルダ"
    strTargetFileName = "テスト.xlsx"
    
    'ファイルの移動
    Name strBaseFilePath & "\" & strTargetFileName As strDstFilePath & "\" & strTargetFileName
End Sub

f:id:ray88:20210711182534p:plain