Select a file instead of selecting the file's destination folder

dedark05

New Member
Joined
Mar 31, 2016
Messages
34
Hi Everyone,

Please bare with me because i'm not an expert in VBA, the existing code here were made by the help of some people here and in other excel forums.

https://www.dropbox.com/s/bth84jl5pi9u76c/Mainfile.xlsm?dl=0 <--this is the excel file with the details of what I wanted to change) and the sample *.txt file that I want to paste in the excel --> https://www.dropbox.com/s/i4ch43ztsmmrd7v/Sample%20txt.txt?dl=0

if you dont have dropbox account, just click on the "No thanks, continue to view →" to view the file/ and you can download it also

I want to change the vba code in which instead of selecting the destination folder of the file I want when I press the button, It will select directly the file. The file in in txt format.

I hope someone can help me with this also.

Thank you,
Dean
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi Dean:

You should be able to do this by changing
Code:
.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
to
Code:
.FileDialog(msoFileDialogFilePicker).SelectedItems(1)

Regards,

CJ
 
Upvote 0
Correction to my previous post:

Change
Code:
.FileDialog(msoFileDialogFolderPicker).Show<strike></strike>
to
Code:
.FileDialog(msoFileDialogFilePicker).Show<strike></strike>

You can then assign a variable the value of .FileDialog(msoFileDialogFilePicker).SelectedItems(1)<strike></strike>

Regards,

CJ
 
Upvote 0
Hi Dean:

You should be able to do this by changing
Code:
.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
to
Code:
.FileDialog(msoFileDialogFilePicker).SelectedItems(1)

Regards,

CJ

Tried that but it gives an error and will yellow highlight this code
Code:
For Each file In fso.getfolder(dataFolderPath).Files
 
Upvote 0
Isn't that code for extracting the one .txt file from the folder? If you use filepicker to have the user select the file then you shouldn't need to do that at all, so it seems to me that you can eliminate it and just have the line: Call ImportTextFile(file, WS_CollectData).

Regards,

CJ
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,178
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top