howardching
asked on
Get the Date Created in the Property Summary of a Excel File
How to get the Date Created in the Property Summary of a Excel File in VBA?
ASKER
The code only gives me the date created under "GENERAL" Tab, not the one under Summary Tab. In fact the file was created by scheduler at 6:02 and sent to me by email. I save the file to my hard disk at 09:17. Your code give me 09:17 not 6:02.
Hi Howard,
Sorry, didn't realise exactly which one you meant.... this code works in vbscript, but I don't have Excel in front of me to test with. Let me know how you go, as it may need a slight bit of tweaking to get it into VBA
Sorry, didn't realise exactly which one you meant.... this code works in vbscript, but I don't have Excel in front of me to test with. Let me know how you go, as it may need a slight bit of tweaking to get it into VBA
Sub GetDateCreated()
'Define file name and path to file
strPath = "C:\temp"
strFilename = "excelfile.xls"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strPath)
Set objFolderItem = objFolder.ParseName(strFileName)
strMyDate = objFolder.GetDetailsOf(objFolderItem, 31)
MsgBox strFilename & " was created on " & strMyDate
End Sub
ASKER
Sorry error:
Object variable or With Block Variable not set
Object variable or With Block Variable not set
I've just cut and paste this into a new Excel macro and it works fine
Obviously you need to customise lines 2 and 3 to reflect the file you want to check.
When you get the error, hit debug - which line does it have a problem with?
Obviously you need to customise lines 2 and 3 to reflect the file you want to check.
When you get the error, hit debug - which line does it have a problem with?
ASKER
I run the code in Access not Excel
The problem is from the following line
Set objFolderItem = objFolder.ParseName(strFil eName
The codes are:
Private Sub Command0_Click()
strPath = "L:\Capex Small Tools\Source\Yardi Daily Source\Job"
strFileName = "Job_Details_Report_.all_2 0110426.xl s"
Set objShell = CreateObject("Shell.Applic ation")
Set objFolder = objShell.Namespace(strPath )
Set objFolderItem = objFolder.ParseName(strFil eName)
strMyDate = objFolder.GetDetailsOf(obj FolderItem , 31)
MsgBox strFileName & " was created on " & strMyDate
End Sub
The problem is from the following line
Set objFolderItem = objFolder.ParseName(strFil
The codes are:
Private Sub Command0_Click()
strPath = "L:\Capex Small Tools\Source\Yardi Daily Source\Job"
strFileName = "Job_Details_Report_.all_2
Set objShell = CreateObject("Shell.Applic
Set objFolder = objShell.Namespace(strPath
Set objFolderItem = objFolder.ParseName(strFil
strMyDate = objFolder.GetDetailsOf(obj
MsgBox strFileName & " was created on " & strMyDate
End Sub
Sorry, didn't realise parseName wasn't usable in VBA, try this instead and let me know how you get on
Sub GetDateCreated()
'Define file name and path to file
strPath = "L:\Capex Small Tools\Source\Yardi Daily Source\Job"
strFilename = "Job_Details_Report_.all_20110426.xls"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strPath)
For Each arrFileName in objFolder.Items
If objFolder.GetDetailsOf(arrFileName, 0) = strFilename Then
strMyDate = objFolder.GetDetailsOf(arrFileName, 31)
End If
Next
MsgBox strFilename & " was created on " & strMyDate
End Sub
ASKER
Error "Object variable or With Block Variable not set" at the following line
For Each arrFileName In objFolder.Items
My Code:
strPath = "L:\Capex Small Tools\Source\Yardi Daily Source\Job"
strFileName = "Job_Details_Report_.all_2
Set objShell = CreateObject("Shell.Applic
Set objFolder = objShell.Namespace(strPath
For Each arrFileName In objFolder.Items
If objFolder.GetDetailsOf(arr
strMyDate = objFolder.GetDetailsOf(arr
End If
Next
MsgBox strFileName & " was created on " & strMyDate
Hi,
This error would generally occur if the file did not exist, the path was incorrect, or the account you are running the code as does not have permissions to that location.
Please could you check these criteria
This error would generally occur if the file did not exist, the path was incorrect, or the account you are running the code as does not have permissions to that location.
Please could you check these criteria
ASKER
The file is correct and the file exist.
ASKER
The path is correct and the file exists.
ASKER
In fact when i test the content of the following line in debug mode, the error "Object variable or With Block Variable not set" occur
? objShell.Namespace(strPath )
? objShell.Namespace(strPath
Is this running as a macro in Access? or how are you running it?
Are you able to post the file for me to check (or is it confidential).
Only reason I ask is that I cannot replicate your error unless I type in the path name incorrectly. I will have another look in the morning though
Are you able to post the file for me to check (or is it confidential).
Only reason I ask is that I cannot replicate your error unless I type in the path name incorrectly. I will have another look in the morning though
ASKER
I put your code in the click event of a button in a form in Access. I click the button and I get the error message.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window