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
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