Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Get Dimensions of Image File Outside Excel

Does anyone know how to retrieve the image size (width and height) in pixels
of an image that is not inside a spreadsheet?

When I hover my mouse pointer over images on my desktop the image size pops
up in Windows Vista, but I don't know how to retrieve this particular
attribute of the file from inside Excel 2007.

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Get Dimensions of Image File Outside Excel

If you check out the link below, I have a script that uses the
"Shell.Application" object to retrieve the dimensions of various types of
picture files as part of the process. You will have to wade through the
other stuff it's doing but it should be easy enough to incorporate. The key
is going to be that you will first need to retrieve the complete file name
including the path (I use WScript arguments as the script is designed so the
user can drag the picture into the file and have it do its thing). I'm
still running WinXP and Excel 2003 so I won't presume to be able to share
exactly how you will need to approach file name retrieval.
http://www.microsoft.com/technet/scr.../cscme009.mspx


Steve Yandl



"Lazzaroni" wrote in message
...
Does anyone know how to retrieve the image size (width and height) in
pixels
of an image that is not inside a spreadsheet?

When I hover my mouse pointer over images on my desktop the image size
pops
up in Windows Vista, but I don't know how to retrieve this particular
attribute of the file from inside Excel 2007.

Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Get Dimensions of Image File Outside Excel

Steve:

That's what I was looking for. The FileSystemObject and the GetDetailsOf
method.

I had to change the GetDetailsOf method constant from 26 to 31 to return the
image dimensions. 26 returned nothing. I checked the FSO documentation but
could not find anything on this. Perhaps it is because I am using Windows
Vista.

Using GetDetailsOf constant 31 returns the image dimensions, but enclosed in
mystery characters that appear as question marks on my computer. That's the
reason for the additional string manipulation.

Perhaps someone can explain the change in the constant, or improve upon my
code.

Thank you for your help.

Function GetImageDimensions(ByVal strPath As String, Optional ByRef lngWidth
As Long, Optional ByRef lngHeight As Long) As Boolean

Dim objFSO As New FileSystemObject
Dim objShell As Object
Dim objFolder As Object
Dim varFileName As Variant
Dim strDimensions() As String

ReDim strDimensions(0)

Const filePropName = 0
Const filePropType = 2
Const filePropDimensions = 31 '26?

If objFSO.FileExists(strPath) Then

GetImageDimensions = True

Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.Namespace(objFSO.GetParentFolderName(strP ath))

For Each varFileName In objFolder.Items

If objFolder.GetDetailsOf(varFileName, filePropName) =
objFSO.GetFileName(strPath) Then
strDimensions(0) = objFolder.GetDetailsOf(varFileName,
filePropDimensions)
If InStr(strDimensions(0), " x ") 0 Then
strDimensions = Split(strDimensions(0), "x")
lngWidth = CLng(Mid(Trim(strDimensions(0)), 2))
lngHeight = CLng(Mid(Trim(strDimensions(1)), 1,
Len(Trim(strDimensions(1))) - 1))
Exit For
Debug.Print lngWidth
Debug.Print lngHeight
End If
End If
Next

End If

Set objFSO = Nothing
Set objFolder = Nothing
Set objShell = Nothing

End Function
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Get Dimensions of Image File Outside Excel

The article in this link is what I used to get started. I suspect that your
issue is rooted in changes made in Vista. Perhaps something in the article
will help you search for updated information for a Vista system.

http://www.microsoft.com/technet/scr....mspx?mfr=true

Steve


"Lazzaroni" wrote in message
...
Steve:

That's what I was looking for. The FileSystemObject and the GetDetailsOf
method.

I had to change the GetDetailsOf method constant from 26 to 31 to return
the
image dimensions. 26 returned nothing. I checked the FSO documentation but
could not find anything on this. Perhaps it is because I am using Windows
Vista.

Using GetDetailsOf constant 31 returns the image dimensions, but enclosed
in
mystery characters that appear as question marks on my computer. That's
the
reason for the additional string manipulation.

Perhaps someone can explain the change in the constant, or improve upon my
code.

Thank you for your help.

Function GetImageDimensions(ByVal strPath As String, Optional ByRef
lngWidth
As Long, Optional ByRef lngHeight As Long) As Boolean

Dim objFSO As New FileSystemObject
Dim objShell As Object
Dim objFolder As Object
Dim varFileName As Variant
Dim strDimensions() As String

ReDim strDimensions(0)

Const filePropName = 0
Const filePropType = 2
Const filePropDimensions = 31 '26?

If objFSO.FileExists(strPath) Then

GetImageDimensions = True

Set objShell = CreateObject("Shell.Application")
Set objFolder =
objShell.Namespace(objFSO.GetParentFolderName(strP ath))

For Each varFileName In objFolder.Items

If objFolder.GetDetailsOf(varFileName, filePropName) =
objFSO.GetFileName(strPath) Then
strDimensions(0) = objFolder.GetDetailsOf(varFileName,
filePropDimensions)
If InStr(strDimensions(0), " x ") 0 Then
strDimensions = Split(strDimensions(0), "x")
lngWidth = CLng(Mid(Trim(strDimensions(0)), 2))
lngHeight = CLng(Mid(Trim(strDimensions(1)), 1,
Len(Trim(strDimensions(1))) - 1))
Exit For
Debug.Print lngWidth
Debug.Print lngHeight
End If
End If
Next

End If

Set objFSO = Nothing
Set objFolder = Nothing
Set objShell = Nothing

End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get image dimensions fishbyname Excel Programming 8 March 20th 07 02:22 PM
Help to insert image from a file in Excel with the help of C# Il' Excel Programming 1 October 12th 06 10:30 AM
Print *.tif image file from vba excel marcus. Excel Programming 0 May 25th 04 01:56 AM
Save Excel chart to file with given dimensions Thomas Wieser Excel Programming 1 April 10th 04 05:27 PM
Export the worksheet background image as an image file - possible? DataFreakFromUtah Excel Programming 2 April 10th 04 04:49 PM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"