|
▼初心者 さん ウッシさん
こんばんは。
Sub DataBkup()
Dim FSO As Object
Dim MyFile As Variant
Dim MyPath As Variant
Dim vFile As Variant
Dim Cnt As Long
Dim FileName As String
Set FSO = CreateObject("Scripting.FileSystemObject")
MyFile = "C:\test.txt" 'データファイルをフルパスで指定
MyPath = "C:\backup\" 'コピー先のフォルダを指定
FSO.CopyFile MyFile, MyPath
Set vFile = FSO.GetFile _
(MyPath & Right(MyFile, Len(MyFile) - InStrRev(MyFile, "\")))
FileName = Format(Now(), "mmdd_hh_mm") & Right(MyFile, 4)
Cnt = 1
Do While FSO.FileExists(MyPath & FileName)
FileName = Format(Now(), "mmdd_hh_mm") & "_" & _
Cnt & Right(MyFile, 4)
Cnt = Cnt + 1
Loop
vFile.Name = FileName
Set vFile = Nothing
Set FSO = Nothing
End Sub
あまり綺麗なコードではありませんが、
とりあえず動くと思われます。
|
|