VBA FileSystemObject - finding dimensions of picture

Associate
Joined
26 Feb 2004
Posts
970
Location
China (Qinhuangdao)
Hi - I'm trying to find the dimensions of a file using the FileSystemObject in VBA.

I see I can get most properties for a file, e.g. Attributes, DateCreated, Name, Parent Folder, path, size, type, etc. but I want to know what resolution the picture is.

I'm using the standard imagebox in Access 2002. Each record has a field storing the filename and path, and automatically changes the imagebox to this picture, when the user moves to a new record.

The trouble is, my database takes forever to open very large res. pictures. And I want to warn the user before it opens. Small pictures get displayed fairly quickly, so I would have no warning if it was below a certain resolution.

Thanks!
 
Not sure whether this will work in Access, but this is how you would get the info in WSH.

Code:
lFolder = [i]"folder path"[/i]
lFile = [i]"filename"[/i]

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(lFolder)
Set objItem = objFolder.ParseName(lFile)
dimensions = objFolder.GetDetailsOf(objItem, 26)

WScript.Echo  dimensions

You can use 27 and 28 in the second argument of GetDetails of to bring back the width and height separately too.

Alternatively you could look at the file size as this is likely to be the determining attribute as to whether the picture takes a long time to open.
 
Back
Top Bottom