Accessing a file header

J

Jay

Is there a way to access the header information of a file? I am
thinking of JPEG and GIF files, where I want to find the horizontal
and vertical pixel sizes of these and put these pixel sizes into a
Word table.
 
D

Dr. Stephan Kassanke

Jay said:
Is there a way to access the header information of a file? I am
thinking of JPEG and GIF files, where I want to find the horizontal
and vertical pixel sizes of these and put these pixel sizes into a
Word table.

Jay,

http://abstractvb.com/code/code677.asp seems to be exactly what you are
looking for (for jpeg files). And http://www.vishwatech.com/c6/v2/C1726.html
lists a function for gif files.

If you are looking for a similar approach for BMP files ... google will
help you ;-)

cheers,
Stephan
 
J

Jay

Thanks Stephan,

I had a look at these and have got the jpeg and gif ones working. One
problem is that if the file doesn't exist, it creates a blank file.
I'd prefer to get an error if the file doesn't exist. How do I do
this? Is there a VBA command to check for a file's existence? Here
some example code...

Dim Fnum as integer
Dim Filename as string

Filename = ????

Fnum = FreeFile
Open Filename For Binary As #Fnum
 
D

Dr. Stephan Kassanke

Jay said:
Thanks Stephan,

I had a look at these and have got the jpeg and gif ones working. One
problem is that if the file doesn't exist, it creates a blank file.
I'd prefer to get an error if the file doesn't exist. How do I do
this? Is there a VBA command to check for a file's existence? Here
some example code...

Dim Fnum as integer
Dim Filename as string

Filename = ????

Fnum = FreeFile
Open Filename For Binary As #Fnum

Hi Jay,

here is a file exists function from J Walkenbach.

Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True _
Else FileExists = False
End Function

Check the existence before you try to access the file

if FileExists(FName)= false then
Exit sub
end if
' further code

cheers,
Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top