Insert multiple files with Dialogs(wdDialogInsertFile)

Z

zsplash

Using Dialogs(wdDialogInsertFile), I am only able to insert a file at a
time. Is there any way that I can use this Dialog to select several files
to insert into the active document at once? If not, how would you suggest
coding to insert several files at once? (Order of file insertion is
unimportant -- I just want each inserted file to be separated by
pagebreaks.)

TIA
 
Z

zsplash

Can you give a little more detail? I search for CommonDialog on Help and
get nothing.

st.
 
Z

zsplash

Okay. I just located John Percival's web "tutorial" and sort of understand
the OCX method of accessing the CommonDialog. How do you indicate flags?
For example, in this case I need the flag "cdlOFNAllowMultiselect(&H200)".
How is my flag syntax (and position) wrong in the following test code?:
Private Sub Command1_Click()
On Error Resume Next 'error handler
CommonDialog1.CancelError = True
' CommonDialog1.InitDir = Dir1.Path -- only with VB (not VBA)
CommonDialog1.ShowOpen
CommonDialog1.Flags = cdlOFNAllowMultiselect(&H200) ' multi-file
selection
If Err.Number = cdlCancel Then
MsgBox "You clicked cancel, which is " & Err.Number
Err.Clear
Else
MsgBox "You chose: " & CommonDialog1.FileName
MsgBox "Filename: " & CommonDialog1.FileTitle
MsgBox "Path: " & Left$(CommonDialog1.FileName, _
Len(CommonDialog1.FileName) - Len(CommonDialog1.FileTitle))
End If
On Error GoTo 0 'turn off error handler
End Sub
 
Z

zsplash

So, please answer this: If I cannot insert multiple files into a Word
document normally (i.e., Insert, File --> I can only select one file at a
time to insert), would all the rigamarole of a CommonDialog control enable
me to do insert more than one file, or not?
 
M

martinique

To use multiple flags with the common dialog you OR them:

With MyDialog
.Flags = cdlOFNFileMustExist OR cdlOFNExplorer
:

If you enable multi-selection, the .FileName property will contain either
the full path and name of the selected file (if only one was selected) or a
NULL-delimited list of which the first element is the path and the
subsequent elements are the unqualified filenames. The Split() function
makes it easy to deal with the list.
 
Z

zsplash

So, I've messed around with this for awhile. What I really wanted to do was
insert multiple files (at once) into one document. I don't think the Common
Dialog allows for that (only to Open multiple files), am I right?

TIA
 
Z

zsplash

Excuse me, I just figured out how to insert multiple files using Common
Dialogs box, as you suggested, Martinique. (Saving the multiplely-selected
files in a listbox, then retrieving those values from the listbox to insert
into the active document.)

Is there a way to use the Common Dialogs box without using a userform? (I
didn't understand John Percival's tutorial on API's in this regard.)

TIA
 
Top