Reading image size?

C

Charlotte E

I have a number of images on a server drive, and I can easily put the path
and name of the image into a variable, i.e.

EngineMap = "S:\EmgineMaps\EngineMap 11.BMP"

The engine maps could also be in any image format, i.e.

EngineMap = "S:\EmgineMaps\EngineMap 123a.JPG"
EngineMap = "S:\EmgineMaps\EngineMap 42ed.TIFF"
EngineMap = "S:\EmgineMaps\EngineMap w3a.GIF"

But they are all in various pixel size, and I need to know the pixel size of
the images....

How can I read the pixel size of an image via Excel VBA?


Thanks in advance...

CE
 
J

Javed

Dear CE,I have tried to give a outline.You can modify it according to
need.

This code will prompt for a folder (Containing pictures).Select a
folder only.Then it will show you the Dimension of the pic.

Sub sd()

Dim sh As New Shell, fol As Shell32.Folder3
Dim FolPath As String, i As Long, PicNum As Long

With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = True
.ButtonName = "Choose Folder"
.InitialView = msoFileDialogViewList

If .Show Then
Set fol = sh.Namespace(.SelectedItems(1))

PicNum = fol.Items.Count

For i = 1 To PicNum
MsgBox fol.GetDetailsOf(fol.Items.Item(i), 26)
Next i

End If

End With


End Sub
 
W

Walter Briscoe

In message <[email protected]
s.com> of Sat, 16 Apr 2011 06:12:46 in microsoft.public.excel.programmin
g said:
Dear CE,I have tried to give a outline.You can modify it according to
need.

This code will prompt for a folder (Containing pictures).Select a
folder only.Then it will show you the Dimension of the pic.

Sub sd()

Dim sh As New Shell, fol As Shell32.Folder3

[snip]

I run Microsoft Office Excel 2003(11.8332.8333) SP3.
My System is Windows Vista Business Service Pack 2.

I was not particularly surprised that compiling the code supplied
resulted in the highlighting of "sh As New Shell" and a "Compile error:
User-defined type not defined" MsgBox.

The help on this error says "... The type is a valid type, but the
object library or type library in which it is defined isn't registered
in Visual Basic.
Display the References dialog box, and then select the appropriate
object library or type library. ..."

The References dialog box can be selected in the VBE from
Tools\References..." when code is not running.
I successfully guessed a relevant reference was "Microsoft Shell
Controls and Automation".

The list of loaded references is a characteristic of the Excel
installation. A change made, while running code in one file, is carried
through to all files.

Can somebody please point me to a logical process for selecting a
reference from the several hundred which seem to be available?

(There is an appropriate probe in 3-7.VBS in "Windows Scripting
Secrets". That depends on a "typelib.decoder" object which is private to
the book. Astoundingly, I still have both book and CD. ;)

Is there anything one can put in code to cause reference satisfaction?
e.g. something like 'needs "Microsoft Shell Controls and Automation"'.

References provide early binding. However, it seem to impose conditions
on any machine running code using it. I hope that, as well as checking
name usage at compile time, early bound code runs faster than late.

I suppose I shall have to start using early binding to see if I like it.

Javed, thanks for challenging me!
 

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