Link to home
Start Free TrialLog in
Avatar of alateos
alateos

asked on

File manipulation with VBA

Hi,

I would like to be able to change file attributes using vba. Also, I would like to see creation date and last accessed date.

Here's an example of what I'd like to do with my code:
1) Change attribute of a file to hidden, read-only, or archive
2) Get the last access date of the file or last modified date.

I would like this code to run for all files in a folder X.
Avatar of PaulHews
PaulHews
Flag of Canada image

1.  Use SetAttr
example:
SetAttr Path, vbHidden Or vbSystem

2. Use FileDateTime, which returns date created or modified

Dim dt as Date
dt = FileDateTime(Path)

For last modified date, you should consider the FileSystemObject...
>For last modified date, you should consider the FileSystemObject...

Meant to be last access date...  FileSystemObject can get all the different types of file date/time stamps:

Example:

Dim fso, file, createdate
Set fso= CreateObject("Scripting.FileSystemObject")
Set file= fso.GetFile("C:\temp\test.txt")
msgbox "Created " &  file.DateCreated
msgbox "Modified " & file.DateLastModified
msgbox "Last accessed " & file.DateLastAccessed

Avatar of alateos
alateos

ASKER

thanks for your reply Paul... could you please show me a full practical example... where the app looks through a folder... also please show how one can set the attribute in the example
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial