basファイルの上書き。
Xxxx(職員名).xlsmファイルを開いたときに、指定のフォルダ内に、更新日時の新しい“yyyy.bas”と“zzz.bas”があれば、古いbasファイルを新しいbasファイルに書き換えたい。
前任者の残したコード
エラーは出ませんが、正しくも動いていない。
標準モジュールに書いてあります。
Sub UpdateBasFile()
Dim FolderPath As String
Dim BasFileName As String
Dim BasFile As String
Dim NewestFile As String
Dim NewestDate As Date
Dim FileDate As Date
' フォルダのパスを設定 FolderPath = "指定したパス" ' BASファイル名を設定 BasFileName = "yyyy.bas" ' 指定されたフォルダ内のすべてのBASファイルをチェック BasFile = Dir(FolderPath & "\" & BasFileName) Do While BasFile <> "" FileDate = FileDateTime(FolderPath & "\" & BasFile) If FileDate > NewestDate Then NewestDate = FileDate NewestFile = BasFile End If BasFile = Dir Loop If NewestFile <> "" Then Dim ThisWorkbookPath As String ThisWorkbookPath = ThisWorkbook.Path FileCopy FolderPath & "\" & NewestFile, ThisWorkbookPath & "\" & BasFileName End If
End Sub