Change date folder (Directory)

Maurizio

Well-known Member
Joined
Oct 15, 2002
Messages
687
Office Version
  1. 2007
Platform
  1. Windows
Is it possible with VBA change date folder (Directory) and subfolder (SubDir)?

Tia.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Sorry Paul,
but I want CHANGE DATE CREATION of a folder.
Bye
 
Upvote 0
Hello, it's my understanding that this can only be done on Windows platforms after 9X, i.e., 2000/NT (XP?) via VBA. If you're in this position, give the following a whirl:

Code:
Option Explicit

Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile _
    As Long, lpCreationTime As FILETIME, lpLastAccessTime As _
    FILETIME, lpLastWriteTime As FILETIME) As Long
    
Private Declare Function GetFileTime Lib "kernel32" _
(ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As _
FILETIME, lpLastWriteTime As FILETIME) As Long

Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
End Type

Private Declare Function SystemTimeToFileTime Lib "kernel32" _
    (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
    
Private Declare Function FileTimeToSystemTime Lib "kernel32" _
    (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
    
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" _
(lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long

Private Declare Function FileTimeToLocalFileTime Lib "kernel32" _
    (lpFileTime As FILETIME, _
    lpLocalFileTime As FILETIME) As Long

Private Declare Function CreateFile Lib "kernel32" _
   Alias "CreateFileA" _
   (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, _
   ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) As Long


Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As _
    Long) As Long

Private Const OPEN_EXISTING = 3
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_FLAG_BACKUP_SEMANTICS = &H2000000
Private Const FILE_SHARE_DELETE As Long = &H4

Private Sub HitIt(myFil As String)
Dim hndFile As Long, st As SYSTEMTIME, ft As FILETIME, ftSystem As FILETIME
hndFile = CreateFile(myFil, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ _
    Or FILE_SHARE_DELETE, 0&, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0&)
If hndFile = 0 Then Exit Sub
st.wYear = 2002 'Year
st.wDay = 25   'Day
st.wMonth = 12 'Month
st.wHour = 0  'Hour
SystemTimeToFileTime st, ft
LocalFileTimeToFileTime ft, ftSystem
SetFileTime hndFile, ftSystem, ftSystem, ftSystem
CloseHandle hndFile
End Sub

Sub Convrt()
Dim fso As Object, subFolders As Object, MyFl As String, folderObject As Object
MyFl = ("c:\temp\test") ''Set your Root Folder
HitIt (MyFl)
Set fso = CreateObject("Scripting.FileSystemObject")
Set subFolders = fso.GetFolder(MyFl).subFolders
For Each folderObject In subFolders
    HitIt (MyFl & "\" & folderObject.Name)
Next
End Sub

FYI, the Scripting subfolder trick only goes one subfolder level deep. You'll need to set up something recursive if you want to nail all of 'em. 'Tis a start. Bon chance.
 
Upvote 0
Hi Oliver Nate,
unfortunately I'm using w98 Se and your solution cannot run Ok!
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,300
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top