PDA

View Full Version : Solved: Can't figure out why this is not working



bassnsjp
02-15-2013, 08:53 AM
OS: Windows 7 and MS Office: 2010
OS: Windows XP and MS Office: 2003

Issue occurs in both environments above.

I have a macro in Outlook that is functioning properly. I would like to now enhance its capability by allowing the user to select the output directory vice doing a copy & paste or typing it in. I searched the internet and found the following code in multiple places so I assume that it works. It should allow the user to select a directory / folder from the selection window. However I'm getting the "Object doesn't support this property or method" and quite frankly I'm stumped as to why. The line causing the error is marked below. In Outlook I have "MS Scripting Runtime" and "MS Outlook <version> Object Library" selected in References among a few others that are defaulted. Is there some other References that need to be selected? Any assistance would be GREATLY appreciated. Thank you in advance for your time.


Function GetFolder(Optional startFolder As Variant = -1) As Variant
Dim fldr As FileDialog
Dim vItem As Variant
Set fldr = Application.FileDialog(msoFileDialogFolderPicker) 'Error is here
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
If startFolder = -1 Then
.InitialFileName = Application.DefaultFilePath
Else
If Right(startFolder, 1) <> "\" Then
.InitialFileName = startFolder & "\"
Else
.InitialFileName = startFolder
End If
End If
If .Show <> -1 Then GoTo NextCode
vItem = .SelectedItems(1)
End With
NextCode:
GetFolder = vItem
Set fldr = Nothing
End Function

skatonni
02-19-2013, 01:23 PM
Some VBA is specific to the application. Excel in this case.

Try this generic VBA
http://www.vbaexpress.com/kb/getarticle.php?kb_id=284

bassnsjp
02-21-2013, 06:20 PM
I found another method by doing a object shell, which works and satisfies my needs, but still would like to get the above to work. Thank you for your link. I haven't had the opportunity to try it, but hopefully will soon.