PDA

View Full Version : Problem selecting file or folder



GOGGS75
01-05-2011, 12:06 PM
Hi,

I have created a macro on WORD that requires the user to select a folder. Using the 'Application.FileDialog' option I have been able to set this up on WORD 2007 but there is a slight problem on WORD 2003.

The commands I have used to select a folder are as follows:

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "C:\Users\Goggs\Documents\Word Documents\AEGON\"
.Title = "Select the folder to save individual invoices to"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then
OUTCOME = "NOEXTRACT": GoTo FINALMSG
Else
EXTRACT = .SelectedItems(1)
End If
End With

The slight problem is that WORD 2003 treats a folder as being selected whenever the enter key is pressed. This leaves the mouse the only way of changing drive or moving back one folder. As wanted WORD 2007 only treats a folder as being selected when the OPEN button is clicked with the mouse

Does anyone know of a way around this problem.

Thanks for any advice

Goggs75

Tinbendr
01-05-2011, 01:39 PM
Another way.

Sub TEST()
ChDir "C:\Users\Goggs\Documents\Word Documents\AEGON\"
With Dialogs(wdDialogFileOpen)
If .Display Then
MsgBox .Name
'Do stuff
End If
End With
End Sub
David

GOGGS75
01-06-2011, 12:04 PM
Hi David

I have tried your code and it starts to solve the problem. Word 2003 still allows you to continue with your file selection after pressing the enter key.

It creates the additional task of having to work out the full path to the file separately. From what I have read elsewhere this is possible.

Thanks for your help

Goggs75