PC Review


Reply
Thread Tools Rate Thread

Allowing user to locate and select a file and save results in stri

 
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      1st Nov 2007
I've got an excel workbook that imports a text file, formats the data it
imports, and posts the text into multiple sheets sorting the data on those
sheet. Right now I have the workbook look for a specific file in a specific
location and consequently my VBA uses the location of the imported file (full
path: c:\documents and settings\username\desktop\filename.txt) in some spots
of the code and the file name (with no path: filename.txt) in other spots.
I'd really like to make this more dynamic and allow the user to actually
browse to and select the file and then have the location of the imported file
and the file name be saved into two strings to be used in the VBA as needed.
Is there an easy way to do this? Thanks!

-Ariel
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      1st Nov 2007
Give this a try, put it where you want to ask for the file, the msgbox is
just to show you what that string will contain.

myFilename1 = Application.GetOpenFilename
MsgBox myFilename1

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"ArielZusya" wrote:

> I've got an excel workbook that imports a text file, formats the data it
> imports, and posts the text into multiple sheets sorting the data on those
> sheet. Right now I have the workbook look for a specific file in a specific
> location and consequently my VBA uses the location of the imported file (full
> path: c:\documents and settings\username\desktop\filename.txt) in some spots
> of the code and the file name (with no path: filename.txt) in other spots.
> I'd really like to make this more dynamic and allow the user to actually
> browse to and select the file and then have the location of the imported file
> and the file name be saved into two strings to be used in the VBA as needed.
> Is there an easy way to do this? Thanks!
>
> -Ariel

 
Reply With Quote
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      1st Nov 2007
Hi John,

Thanks for your help. So... that seems to cover half of what I want to
do... the other half is to parse the results into file name seperate from
path with file name. I'm still new with all of this. Is there an easy way
to break the myFilename1 into two strings: myFilename1 as it is now and then
myFile1 for the file name without the path? I feel a bit like I'm watching
powerball results and I've matched all but the last number which they are
about to read. Thanks!

-Ariel

"John Bundy" wrote:

> Give this a try, put it where you want to ask for the file, the msgbox is
> just to show you what that string will contain.
>
> myFilename1 = Application.GetOpenFilename
> MsgBox myFilename1
>
> --
> -John
> Please rate when your question is answered to help us and others know what
> is helpful.
>
>
> "ArielZusya" wrote:
>
> > I've got an excel workbook that imports a text file, formats the data it
> > imports, and posts the text into multiple sheets sorting the data on those
> > sheet. Right now I have the workbook look for a specific file in a specific
> > location and consequently my VBA uses the location of the imported file (full
> > path: c:\documents and settings\username\desktop\filename.txt) in some spots
> > of the code and the file name (with no path: filename.txt) in other spots.
> > I'd really like to make this more dynamic and allow the user to actually
> > browse to and select the file and then have the location of the imported file
> > and the file name be saved into two strings to be used in the VBA as needed.
> > Is there an easy way to do this? Thanks!
> >
> > -Ariel

 
Reply With Quote
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      1st Nov 2007
I'm sure there are more simple ways, but I don't quite remember since there
is no Find but here is the whole shabang, mypath is the entire path
myfilename is just the filename
mypath = Application.GetOpenFilename

For i = Len(mypath) To 1 Step -1
myfilename = Mid(mypath, i, 1) & myfilename
If Mid(mypath, i - 1, 1) = "\" Then Exit For
Next


MsgBox myfilename

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"ArielZusya" wrote:

> Hi John,
>
> Thanks for your help. So... that seems to cover half of what I want to
> do... the other half is to parse the results into file name seperate from
> path with file name. I'm still new with all of this. Is there an easy way
> to break the myFilename1 into two strings: myFilename1 as it is now and then
> myFile1 for the file name without the path? I feel a bit like I'm watching
> powerball results and I've matched all but the last number which they are
> about to read. Thanks!
>
> -Ariel
>
> "John Bundy" wrote:
>
> > Give this a try, put it where you want to ask for the file, the msgbox is
> > just to show you what that string will contain.
> >
> > myFilename1 = Application.GetOpenFilename
> > MsgBox myFilename1
> >
> > --
> > -John
> > Please rate when your question is answered to help us and others know what
> > is helpful.
> >
> >
> > "ArielZusya" wrote:
> >
> > > I've got an excel workbook that imports a text file, formats the data it
> > > imports, and posts the text into multiple sheets sorting the data on those
> > > sheet. Right now I have the workbook look for a specific file in a specific
> > > location and consequently my VBA uses the location of the imported file (full
> > > path: c:\documents and settings\username\desktop\filename.txt) in some spots
> > > of the code and the file name (with no path: filename.txt) in other spots.
> > > I'd really like to make this more dynamic and allow the user to actually
> > > browse to and select the file and then have the location of the imported file
> > > and the file name be saved into two strings to be used in the VBA as needed.
> > > Is there an easy way to do this? Thanks!
> > >
> > > -Ariel

 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      1st Nov 2007
As John says, there are different ways to get at the file name. Below is
one option.

tgtFullNm = Application.GetOpenFilename
pathArray = Split(tgtFullNm, "\")
fileNm = pathArray(UBound(pathArray))
MsgBox tgtFullNm
MsgBox fileNm


Steve



"ArielZusya" <(E-Mail Removed)> wrote in message
news:16AAED31-403D-466E-9BD3-(E-Mail Removed)...
> Hi John,
>
> Thanks for your help. So... that seems to cover half of what I want to
> do... the other half is to parse the results into file name seperate from
> path with file name. I'm still new with all of this. Is there an easy
> way
> to break the myFilename1 into two strings: myFilename1 as it is now and
> then
> myFile1 for the file name without the path? I feel a bit like I'm
> watching
> powerball results and I've matched all but the last number which they are
> about to read. Thanks!
>
> -Ariel
>
> "John Bundy" wrote:
>
>> Give this a try, put it where you want to ask for the file, the msgbox is
>> just to show you what that string will contain.
>>
>> myFilename1 = Application.GetOpenFilename
>> MsgBox myFilename1
>>
>> --
>> -John
>> Please rate when your question is answered to help us and others know
>> what
>> is helpful.
>>
>>
>> "ArielZusya" wrote:
>>
>> > I've got an excel workbook that imports a text file, formats the data
>> > it
>> > imports, and posts the text into multiple sheets sorting the data on
>> > those
>> > sheet. Right now I have the workbook look for a specific file in a
>> > specific
>> > location and consequently my VBA uses the location of the imported file
>> > (full
>> > path: c:\documents and settings\username\desktop\filename.txt) in some
>> > spots
>> > of the code and the file name (with no path: filename.txt) in other
>> > spots.
>> > I'd really like to make this more dynamic and allow the user to
>> > actually
>> > browse to and select the file and then have the location of the
>> > imported file
>> > and the file name be saved into two strings to be used in the VBA as
>> > needed.
>> > Is there an easy way to do this? Thanks!
>> >
>> > -Ariel



 
Reply With Quote
 
=?Utf-8?B?QXJpZWxadXN5YQ==?=
Guest
Posts: n/a
 
      1st Nov 2007
Steve and John,

Thank you both for your help. This is exactly what I was hoping to learn.
If only winning the powerball was as easy. Thanks again!

-Ariel
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
form & code allowing user to select location of associated file, Thardy Microsoft Access 3 9th Jan 2008 07:43 PM
Re: Allowing user to select a cell in another workbook in VBA Dave Peterson Microsoft Excel Programming 0 12th Sep 2006 12:02 AM
Allowing User to save file =?Utf-8?B?Sm9yZGFu?= Microsoft Excel Programming 5 27th Apr 2006 07:24 PM
Allowing The User To Select Query Criteria =?Utf-8?B?S2llcm9uIFdoaXRl?= Microsoft Access Queries 1 2nd Apr 2006 06:58 PM
Command for allowing user to locate external file. Dave the wave Microsoft Access Form Coding 3 3rd Jun 2004 04:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:07 AM.