FileDialog (FilePicker) doesn't work when word is minimized - a bu

K

Klaus Ambrass

Hi all,

My application needs to minimize Word and then to show a number of
userforms. On one userform I have a button that calls up the FilePicker. The
user picks a file and the application then processes it into a listbox and
other stuff.

However, when the FileDialog is shown it looks ok, except that all the smart
buttons are frozen, even the "Up one level" and "Look in" combo. Furthermore,
when trying to change the current dir by means of the LookIn-combo, Word
freezes or has a tremendous timeout.

Here's the userform's code:

---- code begin ----
Option Explicit
Private Sub UserForm_Initialize()
'ActiveDocument.ActiveWindow.WindowState = wdWindowStateMinimize
Call filePicker
'ActiveDocument.ActiveWindow.WindowState = wdWindowStateNormal
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdAgain_Click()
Call filePicker
End Sub

Private Sub filePicker()
Dim s As String
Dim dFilePicker As FileDialog
Set dFilePicker = Application.FileDialog(msoFileDialogFilePicker)
With dFilePicker
.AllowMultiSelect = False
.ButtonName = "Select"
.Filters.Clear
.Filters.Add "All", "*.*", 1
.Filters.Add "Word documents", "*.doc", 2
.FilterIndex = 2
.Title = "Select a document"
If .Show = -1 Then
Me.txtPath.Text = .SelectedItems(1)
End If
End With

End Sub
---- code end ----

The culprit is the first line in Sub UserForm_Initialize(), where I minimize
Word. If I remove this line, the FileDialog works like a charm. If I put it
in, the buttons freeze up.

I Appreciate that minimizing Word and then showing a modal userform like
this is not the best way. However, this rutine fits mu users' temperament
nicely, and it the buttons should not freeze merely because the main window
is minimized.

Changing the Dialog into Word.Dialogs(wdDialogFileOpen) or using the
FolderPicker instead has the exact same effect (as, I'm sure, the same
low-level dlls are called). Neither does it help to minimze the application
in stead of the ActiveDocument.ActiveWindow. I wonder if it's a bug in a
underlying dll.

I have come no closer than to remark the said line, in order to solve this
problem. I have found none with the exact same problem - not even in the
well-visited Excel Programming forum. Maybe there is no solution?
 
R

Rob

I can't even imagine why the minimize would be needed, but you could try
setting Application.Visible to False (then True again when done) instead of
minimizing the window. It works for me with 2003.
 
K

Klaus Ambrass

Your suggestion works perfectly in my Word 2003 too :)
Thank you a bunch. :)

(Doesn't, however, explain why the FilePicker goes dead just because the
application is minimized)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top