Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Open Folder And Select File


How can I open a folder and select a file?
I need to open the folder of a file and select the file.
This is just like how the Find Target button on the properties of a shortcut works.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Open A Folder And Select A File
Hi
Well open a folder its easy right??: i usually use shellexecute like this:

ShellExecute hWnd, "open", "C:whatever", _
vbNullString, vbNullString, SW_SHOWNORMAL

opens "C:whatever" folder, but...

If the folder have some files like: 1.doc, 2.doc, 3.doc,etc how can i select for example 2.doc "just select not open"

It's there other way to use ShellExecute to open a folder and only select a file?? or we need another code?

Thanks in advance...

Open Folder + Select File
I use this code to open a window in windows showing the folder of a specific file:


Code:
Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long

'In a sub
WinExec "Explorer.exe " & "C:My Folder", 10

But how can I make my file in that folder selected?

Open A Files Parent Folder && Select File
I have the Full path to a file.
I want to open the folder that file is stored in, in an explorer window/my computer window and then select the file.

Microsoft has the option when you DL a file from IE. You can Click 'Open', 'Open Folder' or 'Close' when a DL is complete.
This is the same thing as 'Open Folder'.

Also:
If you go to the properties of a shortcut on the desktop. On the Shortcut tab click 'Find Target...'. An explorer window will open and the file that the shortcut was for will be selected.

Now, lets say I want to find the calculator. It's path is: 'C:windowssystem32calc.exe'.
I'm trying to get 'C:windowssystem32' folder to open, and calc.exe to be selected.

Can anyone help? How can I do this?

Open A Select Folder Dialog With 'Create New Folder' Function
I follow the example in http://www.vbcity.com/forums/topic.asp?tid=87011, it can open a dialog box for selecting folder, but I also want to provide the user to create new folder in the same dialog box. Anyone can give me some suggestion?

Select Folder From Dir And Open
How to select the folder in the dirlistbox and open the filelist inside the folder without double click the folder in the dirlistbox?

Open Dialog - Open Folder Not File
I need to select a folder to work in, but the common controls only allow me to select a file. This will not work since the folder I want to work in only has other folders in it. Is there a way to select a folder instead of file in an open dialog?

Select Random File From Sub-folder
Hi, I'm using the function below to select a random file from a folder and show the path of the file in a messagebox.
How can I select random files from sub-folders as well?

Thanks.


Code:
Option Explicit

Private Sub Command1_Click()
MsgBox ReturnRandomFile("C:MyFolder")
End Sub


Function ReturnRandomFile(ByVal Directory As String) As String
Dim x As Integer, i As Integer, File As String
File = Dir$(Directory)
Do While File <> ""
DoEvents
i = i + 1
File = Dir$
Loop

Randomize
x = Int(i * Rnd) + 1
i = 0

File = Dir$(Directory)
Do While File <> ""
i = i + 1
If i >= x Then Exit Do
File = Dir$
Loop

ReturnRandomFile = Directory & File
End Function

Want Treeview To Select File, Not Just Folder
Hi,
I've found some code that displays a treeview list of directories for selection.
http://www.vba-programmer.com/VB_Cod...ection_API.txt
It works great but I need to be able to select a file, not a folder. Any ideas on how I do this?
Thanks
Sam

Any Application Can Select File And Folder In Dialog
Have you seen File Dialog or same kind of technology in any application to select both of file and folder. I need to make one
for the appliaction to select either file or folder in the same dialog and get the path into my application.

Prompt User To Select A File From A Folder Script?
I'm writing a VB script for an application.

From my stand alone application I can pass values to an existing excel sheet, and I can retrieve values from an existing excel excel.

My next step is to create a situation where the user is offered a open file pop up window that contains all the files in a folder.

ie: I have a folder named "Recipe", when the user hits my "load" button the window pops up the recipe folder and displays all the excel sheets contained in that folder. The user then selects the appropriate file and hits open. This then executes my script which passes the values from my excel spread sheet to my application.

I also need this same type of feature in reverse... where the user can press my "Save" button, which prompts them to name the file, and saves it into my "Recipe" folder as an excel sheet.

I was under the understandign that the open file and save as pop-up windows had a unique text within VB similar to the .MsgBox argument.

Any help with this would be greatly appreciated.

Select And Open The File
How can i open the file
The following code is to select the file, but, what else i need to add in in order fpr me to open the selected file?


Code:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Text1.Text = " File Selected" 'LoadTextFile
End If
End Sub

How To Open And Select A File
I am writing a program and i wan the user to be able to right click on a file in a list i generated and select locate file which will open the containing folder and Select the file, i know how to open the file, and open the folder, but i dont know how to select the file i want, the code im playing with is:

Private Sub Command1_Click()
Dim path As String, filename As String
path = "C:UsersimmerAppDataLocalAresMy Shared Folder" 'containing floder
filename = "80s - styxx - mr roboto.mp3" 'file name

' this will *only* open folder
ShellExecute hwnd, "open", path, "", "", 1
End Sub

any help would be nice

How To Open Each File In A Folder?
Hi folks! I have several folders which contain varying numbers of excel files. In each folder, I want to open each excel file, perform some functions, save, and open the next file.

Your help is much appreciated!

Open File/Folder Box
I want to be able to select a file or a folder like in winamp, or like $sdir/$sfile for those who know mirc.

Does anyone know a way of doing this, thanks!

Open One File Per One In A Folder
Hello
My program generate ever a new .txt-file. With all these files, I need to open one file per one and to find a specific number.
How can I to open one file per one in a folder ?

Thank you to answer me

Best Regards

bonj98

Open File In Folder
My codes are currrently:

Dim theFile As System.IO.FileInfo
Dim theDir As New System.IO.DirectoryInfo("C:Documents and Settings
ypMy DocumentsVB e-assignmentMemberpoints")
For Each theFile In theDir.GetFiles
MsgBox(theFile.Name)
Next

can i know how to put my file name in the folder to display in a listbox? and also those are txt files, which i wish to display the data in the files into the listbox so that i can update in patches. THANK YOU!

Open A XLS File From A Folder In VB
For our project we need to create a small VB application that opens the XLS files from a given folder and runs a (pre-defined) Macro in those XLS files.To do this we imported the .bas file of the macro into VB, but unable to run the same.

If any one have idea on this, please let me know.

VB 6 : Dialog Box To Select File Path But Do Not Open File
Hi,

I am hoping that you can help. I would like to have a dialog box which allows me to choose a file. However, I do not want to open the file but set the filepath as string so that I can use it as a variable later.

Thanks in advance for your help

Danielle

Open All Text File In A Folder One After Another
I want to create a loop that is going to open the first .txt file do some reading in it close it and open the next .txt file in the folder do some reading adn so on...

Open Folder With Selected File
Hi. I want to open the Windows Explorer with one file selected. I've tried this

Code:
'...
Shell ("explorer.exe" & file)
'...

Well, this doesn't work.
Need help. Thank's

VB6 .exe Will Not Open A File In A Folder On A W2000Pro PC
I have written a VB6 application on my XP PC, complied it and tested it by putting all files on a CD and loading them into the proper folder on another PC running XP. When the program loads it tries to access a file in this folder using the classic "C:/Folder Name/FileName". This works fine on my XP PCs but when I load the program into the proper folder on a Windows 2000 Pro PC it say the "path" is wrong or not found.

Is there something about writing on XP PC that makes this type of file access incompatible on a W2000 Pro PC?

Update (3/14 7AM EDT) - Ok, the error is "Run-Time Error 75, Path/File Access Error". Interestingly, when I set a different form as the start I get this error, i.e. the different form has no reference to inputting a file!

By the way, I am 75 years old and I have been working with VB6 for about 2 months so I am a real novice. But I have been working with computers since 1963.

How Can I Open And Read A File From A %folder%
here is the code, I want to replace this path c: ext.txt by %TEMP%

in another words the file will exist in %TEMP%

here is the code:


VB Code:
Dim line As StringDim iFileNo As Integer     iFileNo = FreeFile         Open "C:Missing-Patches.txt" For Input As #iFileNo            Do Until EOF(iFileNo)                Line Input #iFileNo, line                    If line <> vbNullString Then                        List1.AddItem line                    End If            Loop        Close #iFileNo     End Sub

File Open Dialog: Select Multiples?
How would i set up a file open dialog box where you can select multiple files,..and how would i store those file names to an array?

How To Select More Than One File Using Common DialogBox Open
Hello guys,

I have one question here. How to select more than 1 file using common dialogbox Open. As far as I know, it could select only one file each time using mouse. After that we display all the selected files in a textbox. Could we do that?
Thanks

SHELL Open Folder + Focus On The File
hi guys..

i have this line of code here on my cmdOpenFolder


Code:
Shell "explorer.exe " & GetDirName(txtAFileLocation), vbNormalFocus
what i would like to happen is to open the folder containing the file, and that windows explorer would focus on the file.

thank you.

Open File Dialog Box Default Folder
Alright, I'm working on a vba macro in excel 2003.

I want to open a box to allow me to select the file to import (text in this case). The problem is the stupid box always opens to the default user folder. I've tried the Chdir command which will work for subsequent runs of the macro but not the first time the spreadsheet is open. the first time the box opens it always defaults to my documents folder. this is very annoying as I have to browse through 10 network drive sub folders to get where I'm going.

I use the chdir command to set the folder (which works fine except the first time i call myfile at which case it goes to the default folder. is there an easier way to set the default folder (which can change each time the spreadsheet is opened)? help?

here's what i have for code.

Code:
Public Sub import_file()
Dim file_name As String
Dim file_length As Integer
Dim slash_location As Integer

'get worksheet name
file_name = ActiveWorkbook.FullName

slash_location = InStrRev(file_name, "")
file_length = Len(file_name)

test_case_spreadsheet_name = Right(file_name, (file_length - slash_location))

'activeworksheet folder
test_case_spreadsheet_folder = Left(file_name, slash_location)

'opens dialog box
ChDir test_case_spreadsheet_folder
myfile = Application.GetOpenFilename("Text Files,*.txt")



'import settings
Workbooks.OpenText Filename:=myfile, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1)), TrailingMinusNumbers:=True

'easier to see during debug
Columns("B:B").EntireColumn.AutoFit

End Sub

Open File In A Folder With Certain NTFS Permission
hi all
call any one help me to open a file in a shared folder on the network which has a permission to certain user account
programmatically with visual baic 6 without granting the current user a permission to this folder

Opening A Folder Then By Clicking On A File Open That.
I am looking for an example that will let me open a folder then the file by clicking on it.

I am using the commondlg and it opens the folder but when I click on the file
it writes the file name to a tool variable. It doesn't open the file.

Thanks in advance.

Excel Navigate To Folder---open Each File
I've created an Excel2000 macro to process data from several *.csv files. At present, I'm using an InputBox to tell the macro in what folder to find the files. Does anyone know how to arrive at the desired folder by navigating similar to Windows Explorer (perhaps through a form)? And, the macro opens each *.csv file in the folder in turn, closing it before opening the next. Is there a way to do this for each file in the folder on a wildcard basis?

 

Select File To Open Using Macro And Windows Browser?
Hi

What I need to do is write a bit into my macro that lets the user select the file they want to open (more accurately to name the path and filename of a workbook they wish to open) so that i can use the path and filename to open the XLS and then copy some of the data into my new workbook.

The files to import data from are not named with any convention, nor are they located on a fixed location (is a server which can change drive mapping letter depending on the user's computer!). What I wanted to do was have a window pop up (like the standard File, Open window) which allows the user to browse to their XLS and select it.

The macro would then set the path and filename into a variable so the XLS can be opened and referenced.

Is this possible?

Regards

Rob

Multi-select Files Using Open File Dialog API..?
I would like to fill a listbox with files using the Open File dialog API. Anyone have code for doing this?

Auto Select With Open File Dialog Boxes?
Hey All!

Hope everyone's well today.

Alright, here's the thing -

At the moment when my application opens, it allows you to navigate through directories and choose particular files to search and split. It all works beautifully now (thanks to help from you guys!) but the boss has decided he wants it to be scheduled to run automatically while we're not in the office.

So my question is this:

How can I get my program to select only two particular files - out of 23 - from a file list for processing without any input from a user, and process them one after the other?

Or...is there a way to pass the specific filename to the program from a commandline in the scheduled task?

Cheers,
-K-

*edited for spelling and adding extra info*

Open Folder And File - Search (Loop) Help Needed
Hi,

I need some help writing/figuring out if it is possible to perform this using VBA.

I have a main file directory with roughly 100 sub-folders. Within some folders are excel files beginning with the letter ‘J’. I would like to be able to open each sub-folder in turn, if the folder contains a file beginning with a ‘J’ I wish to open the excel doc and search for a field. If the field is found the macro will end, if not the excel document should be closed and the next sub-folder opened and searched.

I am not sure if it is possible to perform this kind of loop using VBA and my main problem comes with my limited knowledge of handling files and folders. Especially where the folder names cannot be hard-coded.

Would anyone be able to explain if this is possible and how one goes about moving through folders in such a way.

Any help would be extremely gratefully received


Edit by Moderator:
Please post Excel questions, in the Excel forum.

Thank you.

Open Text File, Select Text At Position
vb gurus of the world

I'm relatively comfortable with the Shell function and manipulating text in a text file. I'm finding it surprisingly difficult to place the caret and select text, however. Has anyone been here before? If so a few hints would be great!

Bas

New Folder, Folder Exists , File Exist Copy File
Hello,
I want to perform the following task through VB 6.0

How to check Folder if Exist or not , If not exist then create it. If exist then find a given file name Ex. "Abc.Mdb", if exist then delete it and copy new file from App.Path if not exist then copy File from App.Path

Please help me
Farooq

Select Folder
I'm using this code:
http://www.vbforums.com/showthread.p...=select+folder
to select a folder, together with this:

Private Sub kunddisk_Click()
Harddisk.Text = BrowseForFolder(0) & ""
End Sub

But the problem is, if I click cancel in the dialog the "Harddisk.Text" will only be "" instead of leaving the old value, how do I solve this?

Folder Select
Can I use code to browse a dialog to select folder?

Folder Select
I've been using this view FAQ #22234 to allow the user to select a file for some time now, does somebody know of a version I can use that will allow the user to select a folder insted.

Select The Folder From A Directory
I have this path stored in 'main_path'
"c: estcase ester est.ini"

Now I want the valeu of 'main_path'to be:
"c: estcase ester" how can I change this? Does anyone has any experience with this kind of question?

Thanx in advance.

Select A Folder From Dialog?
I know you can choose files from CommonDialog but how do you select a folder or a path in general. Thanks in advance for any help. PS: I know im a nubblet lol

How To Select A Folder From FolderDialog
Hi All

Background: I'm new to programming and as a first assignment i'm trying to create a program that allows a user to click a button, browse to a folder after the folder is chosen i'd like the path to be displayed in a label, after this a button called LIST will be clicked and the program will display all the file names (without path) into a List box or data grid from that folder, which ever is easier. (after this i'll think about more functionality, just trying to keep it simple.

So Far.
I have created a button with the following code

Private Sub BrowseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseButton.Click
Dim strString As String
Dim OpenFile As New FolderBrowserDialog

strString = OpenFile.ShowDialog
If OpenFile.ShowDialog = DialogResult.OK Then


End If


End Sub

This so far opens up the folder dialog, i'm having problems thinking what to do next. Id like to browse to a folder, click ok and the path will be displayed in a label. So i have also created a label.

My Question
Please can you show me how to link the two toghether. Preferably with a brief explanation (if u have time)

Thanks a lot to anyone for your comments and please try and keep it simple

I'm using VB.NET in Visual Studio

Select Folder Dialog
How do I show the Windows' Select Folder dialog? It can't be done using the common dialog control because it doesn't support it.

Select Folder To Save Into
I want to use the common dialog box to select a folder which the user wants to save a load of files in.

When the user click a folder i want that directory path as a result.

When i do it using .ShowSave it will want to save a file, not select a folder to save to later.

I hope you all understand

ILMV

Select Folder Control
is there a folder control, similar to the select folder dialog, and the windows explorer left side (when in explore mode), so i can embed it into a form?

Folder Select Dialog Box
Hiya, Just wondering if there is a way to manipulate the common dialog control to display a select folder type dialog (ie. for a save path without neccessarly having a file to save just yet). Can this be done with the common dialog controls or will I need to make my own dialog?

Folder Select Function
Hi,

Does anyone know the api call to run the folder select dialog box. It is
the one that just brings up the computers drives and network mappings. You
just use it to select a path to the folder rather than the commondialog
which is for specific files....

Thanks
Tom

Select All Files In A Folder And Copy Them.
Hi Guys,

I need to try and add a back up files feature in my app.

At the moment I have a form that lets the user see the files saved by using a browser control with simple code on a buttons event like so:

Code:
Me.brwWebBrowser1.Navigate App.Path & "/Saved/"

I would like to add an additional button that when clicked selects & copys all the files and folders in the Saved folder.........and put them in a folder of the users choice.

If I could figure out how to select and copy all the files being displayed in the browser control I think I could get through the rest??

Thanks in advance for any thoughts.

Browse For Folder: Multi-Select
Hello!

Is it possible to select multiple folders using the Browse For Folder dialog by supplying some special flags?

Regards,
Sebastian Mares

Common Control Folder Select
Is there a control to popup the standard Select Directory window? ive searched but cannot find this.

I thought it was part of a common control, but maybe not. ANy ideas

thanks in advance

Copyright 2005-08 www.BigResource.com, All rights reserved