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 work-around is :
CommandBars.FindControl(ID:=23, Visible:=False).Execute
instead of:
Dialogs(wdDialogFileOpen)

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

The second solution 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 and I am not a programmer.
Anyone can help?
Thanks,
Alfred
 
G

Graham Mayor

I am not sure what it is you are trying to achieve that cannot be achieved
by the Word built-in File-Open menu command however

Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = True
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "Cancelled"
Exit Sub
End If
End With
For i = 1 To fDialog.SelectedItems.Count
Newfile = fDialog.SelectedItems.Item(i)
Documents.Open Newfile
Next i

will open multiple files


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alfred

Dear Graham,

Thanks very much for your answer. Maybe I was not clear enough, but
what I am trying to achieve is the following behavior of the FileOpen
Dialog:
SendKeys “+({TAB})”
Dialogs(wdDialogFileOpen).Application.Caption = " "
Dialogs (wdDialogFileOpen). Show
On Error Resume Next
ActiveDocument.ActiveWindow.Caption = _
ActiveDocument.ActiveWindow.Caption + “


AND keep the ability to select and open multiple files at once from
the FileOpen dialog.
The built-in Word OpenFile dialog does not allow to open multiple
files at once, however.

I am not a programmer (but a writer) and do not know how to use your
FilePicker macro. I added Sub FilePicker() and End Sub and put your
code in between. It gave an error. So I guess I did something wrong!

Please, would you be so kind and explain me 1) how to implement your
macro 2) how to add my desired lines of code in this macro

Thanks!
Alfred
 
G

Graham Mayor

See http://www.gmayor.com/installing_macro.htm

What is it that you think your macro does differently from the menu
command? - apart from add a row of (invisible) spaces to the title bar of
the document, and preventing the selection of multiple documents (which the
standard dialog does allow!)?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alfred

Hi Graham,

In Word I never use a mouse and I do everything with keyboard
shortcuts.

I wrote my macro for the following reasons:

SendKeys “+({TAB})” (in combination with a registry change) makes the
FileOpen dialog start with the first document selected, instead of
having the cursor blinking in the search box (I never have to search
anything, all my files are very well organized in a system of folder
trees).

The other lines have to do with changing the Word titlebar. I use Word
constantly and I know it is called Microsoft Word, I prefer seeing
just the file name.

Dialogs(wdDialogFileSaveAs).Application.Caption = " "
removes ‘Microsoft Word’ from the titlebar

ActiveDocument.ActiveWindow.Caption = _
ActiveDocument.ActiveWindow.Caption + "
"
(after oppressing ‘Microsoft Word’ a hyphen remains that doesn’t allow
itself to be removed; I moved the hyphen therefore to the corner of my
screen, where it will change in 3 dots. Using a date/time add-in for
the titlebar and putting the background and the font to the same
background (black) as the one on the titlebar, makes the hyphen become
invisible.

I will try to implement your macro and combine it with the above
lines, using your Idiots’ Macro Installing program.

Thanks,
Alfred
 

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