Dialog Box

C

cjbailey

Hi,
Can I use the common dialog boxes within word, if so then how!?!?!

I need a browse function which will allow the user to browse the fil
system for files, returning the full path of the file that is selecte
into a text box (txtFileName) I have tried using the word dialog boxe
(Dialogs(wdDialogFileOpen)), but can't find one that will just retur
the path of a selected file.
Cheers,
Chri
 
J

Jezebel

Sure can. Create a UserForm. If the CommonDialog isn't available on your
controls toolbox, right click on the toolbox, select Additional Controls,
check the box beside "Micosoft Common Dialog control".

Then click on the control icon, draw it on your UserForm, then write code a)
to display the form, and b) within the form, to use the control and do
whatever with the result.
 
C

cjbailey

When I try and place the control onto the form it says that "The contro
could not be created because it is not properly licensed
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

If you are using Word XP or later, you can use:

'Declare a variable as a FileDialog object.

Dim fd As FileDialog



'Create a FileDialog object as a File Picker dialog box.

Set fd = Application.FileDialog(msoFileDialogFilePicker)



'Declare a variable to contain the path

'of each selected item. Even though the path is a String,

'the variable must be a Variant because For Each...Next

'routines only work with Variants and Objects.

Dim vrtSelectedItem As Variant



'Use a With...End With block to reference the FileDialog object.

With fd



'Use the Show method to display the File Picker dialog box and
return the user's action.

'The user pressed the action button.

If .Show = -1 Then



'Step through each string in the FileDialogSelectedItems
collection.

For Each vrtSelectedItem In .SelectedItems



'vrtSelectedItem is a String that contains the path of each
selected item.

'You can use any file I/O functions that you want to work
with this path.

'This example simply displays the path in a message box.

MsgBox "The path is: " & vrtSelectedItem



Next vrtSelectedItem

'The user pressed Cancel.

Else

End If

End With



'Set the object variable to Nothing.

Set fd = Nothing

With earlier versions of Word, use

With Dialogs(wdDialogFileOpen)
If .Display Then
'file was selected
MsgBox WordBasic.FilenameInfo$(.Name, 1)
Else
MsgBox "Dialog cancelled
End If
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

If you would post directly to the newsgroups on msnews.microsoft.com or
access the Microsoft Web Interface to the Newsgroups at
http://communities.microsoft.com/newsgroups/default.asp, rather that use
Rubin's crappy website, you would see the other response to your post that
gives you a couple of alternative ways of doing this.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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