File Open with variable directory, that adds to recently used file list?

D

Dan Williams

People have already complained about Word 2003's intermittent failure
of

ChangeFileOpenDirectory "H:\MISC\SpecialDirectory\"
Dialogs(wdDialogFileOpen).Show

when they're trying to initiate the File Open dialog box with a VBA-
specified directory. The response has been that they should use this:

With Dialogs(wdDialogFileOpen)
.Name = "H:\MISC\SpecialDirectory\*.doc"
.Show
End With

However, I gave up on .Show long ago, because after you choose a file,
it fails to add it to the File menu's recently used file list. In
Word 2000, I settled for this distasteful substitute*:

ChangeFileOpenDirectory "H:\MISC\SpecialDirectory\*.doc"
SendKeys "%f" ' ALT+f
SendKeys "o"

This works in Word 2000.

Now, in Word 2003, this fails a lot of the time, bringing you to My
Documents instead. (It sometimes fails for a long time, and it
sometimes works for a long time during which I can't get it to fail,
so please don't just reply it that works OK for you.)

Is there any way to get this to always work, including putting the
file in the recently used file list?

It's such a simple thing to want to do. I know there's an
AddToRecentFiles variable in the Dcoument.Open method, but please
don't say I need to duplicate the whole FileOpen mechanism (as
with .GetOpenFilename in Excel).

Dan Williams
danwPlanet

*Note that I had to use two SendKeys statements, because when you use
SendKeys "^o" ' (Ctrl+o), it inexplicably puts you into Outline View
instead of doing what Ctrl+o is supposed to do.
 
R

Rob

Try this

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogOpen)
fd.InitialFileName = "H:\MISC\SpecialDirectory\*.doc"
If fd.Show Then
Application.RecentFiles.Add fd.SelectedItems(1)
fd.Execute
End If

Set fd = Nothing
 

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