Skip to content

Instantly share code, notes, and snippets.

@YujiFukami
Created January 17, 2024 08:44
Show Gist options
  • Save YujiFukami/cfc1eadf07bfa2834dbadd205b8f57d9 to your computer and use it in GitHub Desktop.
Save YujiFukami/cfc1eadf07bfa2834dbadd205b8f57d9 to your computer and use it in GitHub Desktop.
Public Sub BackupWithDateToFolder(ByRef FullPath As String, _
ByRef BackupFolderPath As String)
'指定ファイルを指定フォルダに日付をつけてバックアップ
'「Microsoft Scripting Runtime」ライブラリを参照すること
'20211102
'20231217 変更
'参考
'https://www.softex-celware.com/post/BackupWithDateToFolder
'引数
'FullPath ・・・バックアップするファイルのフルパス
'BackupFolderPath・・・バックアップ先のフォルダパス
'元のファイル名から日付が付いたファイル名を作成
Dim FSO As New FileSystemObject
Dim FileName As String
Dim Extension As String
Dim BackupFileName As String
FileName = FSO.GetFileName(FullPath)
Extension = FSO.GetExtensionName(FullPath)
BackupFileName = FileName & "_" & _
Format(Date, "YYYYMMDD") & _
"." & Extension
'バックアップ作成
Call FSO.CopyFile(FullPath, _
BackupFolderPath & "\" & BackupFileName)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment