Is this possible


Posted by John K. Moore on September 06, 2001 10:44 AM

I have been trying to write a macro that will retrieve data from an unopened file properties.

This doesn't seem like it would be to difficult since
you can right-click on any file pick properties and view that info. from windows explorer.

Any ideas would be appriciated

Posted by Dax on September 06, 2001 11:03 AM

Hello,
In the VB editor click Tools, References and look for the Microsoft Scripting Runtime and select it.

Code like this will provide you with a files properties:-

Sub FileProperties()
Dim FSObj As New Scripting.FileSystemObject
Dim scrFile As Scripting.File

Set scrFile = FSObj.GetFile("C:\Excel files from T5H8I0\Budget.xls")

'You can now get the properties of the file e.g.
MsgBox "Date created = " & scrFile.DateCreated

MsgBox "Date last modified = " & scrFile.DateLastModified

MsgBox "Size = " & scrFile.Size & " bytes"

MsgBox "File type = " & scrFile.Type
End Sub

HTH,
Dax.

Posted by John K. Moore on September 06, 2001 1:21 PM

Thanks,

That worked perfectly, will this also be able to access the custom properties, I am not sure how to do that and I am most interested in getting data from there.




Posted by Dax on September 06, 2001 2:30 PM

Here are two simple macros to do what you want. If you want the same macro to add/subtract depending on what the user chooses, you'll have to add some coding or (preferably) create a userform.

Sub AddtoCell()
oNumb = ActiveCell.Value
uNumb = InputBox("Enter Number to Add", "Add Number")
nNumb = oNumb + uNumb
ActiveCell.Value = nNumb
End Sub


Sub SubtractfromCell()
oNumb = ActiveCell.Value
uNumb = InputBox("Enter Number to Subtract", "Subtract Number")
nNumb = oNumb - uNumb
ActiveCell.Value = nNumb
End Sub


Assign these macros to hotkeys or to toolbar buttons for quick access.

-Ben