0

I wrote this code to return some properties from file:

 Dim strMTitle As String
 Dim objMshell As Object
 Dim objMfolder As Object
 Dim objMFolderItem As Object
 Dim strMpath As String
 strMpath = "C:\Users\User1\Desktop\Test4\"

 Set objMshell = CreateObject("shell.application")
 Set objMfolder = objMshell.Namespace(strMpath)
 Set objMFolderItem = objMfolder.ParseName("test2.xlsm")

 strMTitle = objMfolder.GetDetailsOf(objMFolderItem, 21)

 Debug.Print strMTitle

The problem is that it keeps returning run time error 91 - Object variable with block variable not set. Weirdest thing is that when I "Hardcode" objMfolder with path like this: Set objMfolder = objMshell.Namespace("C:\Users\User1\Desktop\Test4\") the code works perferct. I use this path in multiple places in my macro so I would really like to "store" it in strMpath and use it like this:

Set objMfolder = objMshell.Namespace(strMpath) 

Please help!

1 Answer 1

1

The code seems to work with the string variable if you use early-binding and the Shell32.Shell as below. Also, .GetDetailsOf with a column argument of 21 returns nothing, but 0 returns the file name.


Option Explicit
'Set Reference to Microsoft Shell Controls and Automation

Sub dural()
 Dim strMTitle As String
 Dim objMshell As Shell32.Shell
 Dim objMfolder As Folder
 Dim objMFolderItem As FolderItem
 Dim strMpath As String
 strMpath = "C:\Users\Ron\Desktop\"

 Set objMshell = New Shell32.Shell
 Set objMfolder = objMshell.Namespace(strMpath)
 Set objMFolderItem = objMfolder.ParseName("20161104.csv")

 strMTitle = objMfolder.GetDetailsOf(objMFolderItem, 0)

 Debug.Print strMTitle
End Sub

Sign up to request clarification or add additional context in comments.

2 Comments

argument 21 returns "Title" property. Thanks Ron
@Pawel Oh well, I guess the file I was testing does not have a Title Glad the code is working for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.