PDA

View Full Version : Solved: Is File a Graphic Type File?



gmaxey
12-04-2012, 09:53 AM
I'm looking for a VBA function to determine if a file path and name represents a graphic type file (e.g., .png, .bmp, .jpg, etc.)

I know that I can evaluate the extension, but that is hardly sailor proof. I also know that I could set up a test where I try to use an invalid type and rely on an error to indicate that the file type is wrong.

I'm looking for a VBA function that will do what I suspect this VB.Net function I found posted does:

Function IsValidImage(filename As String) As Boolean
Try Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(filename)
Catch generatedExceptionName As OutOfMemoryException
'Image.FromFile throws an OutOfMemoryException
'if the file does not have a valid image format or
'GDI+ does not support the pixel format of the file.
Return False End Try Return TrueEnd Function

Thanks.

macropod
12-04-2012, 02:25 PM
Hi Greg,

See: http://www.vbaexpress.com/forum/showthread.php?t=43972&highlight=GetImageFileInfo

gmaxey
12-04-2012, 02:52 PM
Paul,
Thanks!!