opening multiple files at once gives error

A

Alfred

Hi all,
Since many years I use the following macro that suits my needs:

Sub FileOpen ( )
SendKeys “+({TAB})”
Dialogs(wdDialogFileOpen).Application.Caption = " "
Dialogs (wdDialogFileOpen). Show
On Error Resume Next
ActiveDocument.ActiveWindow.Caption = _
ActiveDocument.ActiveWindow.Caption
" "
End Sub

The FileOpen Dialog has one setback, however: it does not allow to
open multiple files at once (‘error 5174, file cannot be found’)
Opening multiple files using a right click also gives an error (‘there
is another active dialog running’)
According to the Microsoft webpages this behavior is by default.

I found two work-arounds or solutions which, however, I cannot get to
work.
The first workaround is :
CommandBars.FindControl(ID:=23, Visible:=False).Execute
instead of:
Dialogs(wdDialogFileOpen)

This gives the error: ‘Method Execute of CommandBarButton failed’

The second is:
Sub ShowFileDialog()
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
End With
End Sub

This macro gives a VB ‘compiling error’. It might be VBA code. If so,
how to implement it in a VB6 macro?

My question in short:
I want to use my original code (as mentioned in the beginning of this
message) and keep the ability of opening multiple files at once
(without extra message boxes, toolbars or buttons). I use Windows XP,
Word 2003 and VB6.
Anyone can help?
Thanks,
Alfred
 
C

Cindy M.

Hi Alfred,
Since many years I use the following macro that suits my needs:

Sub FileOpen ( )
SendKeys “+({TAB})”
Dialogs(wdDialogFileOpen).Application.Caption = " "
Dialogs (wdDialogFileOpen). Show
On Error Resume Next
ActiveDocument.ActiveWindow.Caption =
ActiveDocument.ActiveWindow.Caption
" "
End Sub

The FileOpen Dialog has one setback, however: it does not allow to
open multiple files at once (‘error 5174, file cannot be found’)
Opening multiple files using a right click also gives an error (‘there
is another active dialog running’)
According to the Microsoft webpages this behavior is by default.

I found two work-arounds or solutions which, however, I cannot get to
work.
The first workaround is :
CommandBars.FindControl(ID:=23, Visible:=False).Execute
instead of:
Dialogs(wdDialogFileOpen)

This gives the error: ‘Method Execute of CommandBarButton failed’

The second is:
Sub ShowFileDialog()
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(
FileDialogType:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
End With
End Sub

This macro gives a VB ‘compiling error’. It might be VBA code. If so,
how to implement it in a VB6 macro?

My question in short:
I want to use my original code (as mentioned in the beginning of this
message) and keep the ability of opening multiple files at once
(without extra message boxes, toolbars or buttons). I use Windows XP,
Word 2003 and VB6.
Many, many years ago (15 or so) someone had a workaround for what you
want using the WindowsAPI, but that was WordBasic and I doubt I have it
anymore. I think it involved getting the selection from the dialog box,
then not executing the dialog box, but processing the file names picked
up through the Windows API.

So you'd be much better off using your second method which is, I
believe, the most promising approach. The compile error could be because
you're missing a Reference to a DLL in your VB6 project? Which line of
code causes the error? I'm guessing the one with the msoEnum. You need to make
sure you have a reference to the Office dll and you need to fully qualify the
msoEnum (or use the Long equivalent).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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