ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   form using windows explorer (https://www.excelbanter.com/excel-programming/360538-form-using-windows-explorer.html)

Spike

form using windows explorer
 
Is there a way that i can create a form that acts like windows explorer or
incorporates windows explorer so that a user can follow instructions on the
form and select the relevant file from the windows explorer part of the form?

I can get windows explorer to show by shell etc but need to show
instructions at the same time.

Any advices will be very gratefully received

Many thanks
--
with kind regards

Spike

[email protected]

form using windows explorer
 
use the common dialog box control, or build a control of your own using
list boxes, or (more simply) invoke the File Open command from VBA but
just use this to get the file name - this example will get a text file,
but can be adapted to pick up any file of the users choice

FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")


Spike

form using windows explorer
 
Thank you. I am probably being very dim but i cannot find a control that
will stick windows explorer on a form, i have checked tools/refs for other
libraries etc.

What i want to do is to have a form with instructions on the form and the
form to also show windows explorer so if the user cannot see the file they
need they can go to a different directory.
--
with kind regards

Spike


" wrote:

use the common dialog box control, or build a control of your own using
list boxes, or (more simply) invoke the File Open command from VBA but
just use this to get the file name - this example will get a text file,
but can be adapted to pick up any file of the users choice

FileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")



[email protected]

form using windows explorer
 
You need to right click on the toolbox to get more controls, then you
should find the microsoft common dialog control - from help:-

CommonDialog Control


The CommonDialog control provides a standard set of dialog boxes for
operations such as opening and saving files, setting print options, and
selecting colors and fonts. The control also has the ability to display
help by running the Windows Help engine.

Syntax

CommonDialog

Remarks

The CommonDialog control provides an interface between Visual Basic and
the routines in the Microsoft Windows dynamic-link library Commdlg.dll.
To create a dialog box using this control, Commdlg.dll must be in your
Microsoft Windows SYSTEM directory.

You use the CommonDialog control in your application by adding it to a
form and setting its properties. The dialog displayed by the control is
determined by the methods of the control. Atrun time, a dialog box is
displayed or the help engine is executed, when the appropriate method
is invoked; atdesign time, the CommonDialog control is displayed as an
icon on a form. This icon can't be sized.

The CommonDialog control can display the following dialogs using the
specified method.

Method Dialog Displayed
ShowOpen Show Open Dialog Box
ShowSave Show Save As Dialog Box
ShowColor Show Color Dialog Box
ShowFont Show Font Dialog Box
ShowPrinter Show Print or Print Options Dialog Box
ShowHelp Invokes the Windows Help Engine


The CommonDialog control automatically provides context sensitive help
on the interface of the dialog boxes by clicking:

The What's This help button in the title bar then clicking the item for
which you want more information.


The right mouse button over the item for which you want more
information then selecting the What's This command in the displayed
context menu.
The operating system provides the text shown in the Windows 95 Help
popup. You can also display a Help button on the dialog boxes with the
CommonDialog control by setting the Flags property, however, you must
provide the help topics in this situation.

Note There is no way to specify where a dialog box is displayed.

For More Information To see help topics for each dialog, click on See
Also.


However, I'd still use the Application.GetOpenFilename("Text Files
(*.txt), *.txt") method myself

for example, with a text box visible and a command button you can set
the text box to the file they want by using

TextBox1.Text = Application.GetOpenFilename("Text Files (*.txt),
*.txt")


as I say, change the mask from *.txt to whatever mask you want!


H.A. de Wilde[_4_]

form using windows explorer
 

From Help:

Create a button on your form called cmdSelect_File

Add the following code to Private Sub cmdSelect_File_Click():


'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 an
return the user's action.
'The user pressed the action button.
If .Show = -1 Then

'Step through each string in the FileDialogSelectedItem
collection.
For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is a String that contains the path o
each selected item.
'You can use any file I/O functions that you want t
work with this path.
'This example simply displays the path in a messag
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 = Nothin

--
H.A. de Wild
-----------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...fo&userid=3067
View this thread: http://www.excelforum.com/showthread.php?threadid=53878


Spike

form using windows explorer
 
Thank you both very much extremely helpful, i did not appreciate that the
microsoft common dialogue control was the one i wanted. Anyway as there
appears to me some issue it does not work but have used the GetOpenFileName
which is grand.

Thank you
--
with kind regards

Spike


"H.A. de Wilde" wrote:


From Help:

Create a button on your form called cmdSelect_File

Add the following code to Private Sub cmdSelect_File_Click():


'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


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538789




All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com