Insert Image Path and Dimensions Returned

Eric Strobel

New Member
Joined
Oct 4, 2018
Messages
4
I am trying to be able to insert the path to an image, and have the dimensions and other attributes of the image returned in a cell. I am able to get the dimensions of all the images located in the specified folder when running the macro below:

Sub Dimensions()
Dim sFile As Variant
Dim oShell: Set oShell = CreateObject("Shell.Application")
Dim oDir: Set oDir = oShell.Namespace("C:\Users\estel\Pictures\Saved Pictures")
Dim i As Long


i = 1
For Each sFile In oDir.Items
Cells(i, 1).Value = oDir.GetDetailsOf(sFile, 0)
Cells(i, 2).Value = oDir.GetDetailsOf(sFile, 1)
Cells(i, 3).Value = oDir.GetDetailsOf(sFile, 2)
Cells(i, 4).Value = oDir.GetDetailsOf(sFile, 31)
i = i + 1
Next
MsgBox "Done"
End Sub

The two issues I am having are the following:
1. This code does not use the path located in the desired cell (O12), and requires me to manually change the path through vba.
2. This code lists the desired attributes of all images in the file folder Saved Pictures, when I only want the attributes of the image specified in O12.

I am fairly new to vba so apologize if the solution is simple. Thank you in advance for the help.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
First, let's assume that A2 contains the path, and B2 contains the name of the file. The following macro will place the information for the specified file in cells C2, D2, E2, and F2.

Code:
Option Explicit

Sub Dimensions()
    Dim shellApp As Object
    Dim theFolder As Object
    Dim theFolderItem As Object
    
    Set shellApp = CreateObject("Shell.Application")
    Set theFolder = shellApp.Namespace(Range("A2").Value)
    Set theFolderItem = theFolder.ParseName(Range("B2").Value)
    
    Range("C2").Value = theFolder.GetDetailsOf(theFolderItem, 0)
    Range("D2").Value = theFolder.GetDetailsOf(theFolderItem, 1)
    Range("E2").Value = theFolder.GetDetailsOf(theFolderItem, 2)
    Range("F2").Value = theFolder.GetDetailsOf(theFolderItem, 31)
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,267
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top