PC Review


Reply
Thread Tools Rate Thread

Changing path for import file

 
 
=?Utf-8?B?R3JlZw==?=
Guest
Posts: n/a
 
      19th Jul 2007
My macro imports a couple of csv files that are always located in the
c:\users\username\documents\data folder, with username being the user whose
computer the spreadsheet is being used on. Unfortunately for me, whenever I
make a change to the macro, I have to create a separate copy for each
individual so that the file path to the csv file that's being imported is
correct. The portion of the code that refers to the file reads:

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\username\Documents\Data\Import.csv" _
, Destination:=Range("A3"))
.Name = "Import"

Is there a way to code this so I don't have to change the path for each user?

Thanks for any help.
 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      19th Jul 2007
see if this helps:

dim fPath as string
fPath = "c:\users\" & Environ("username") & "Documents\Data\"

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fPath & "Import.csv" _
, Destination:=Range("A3"))
.Name = "Import"


--


Gary


"Greg" <(E-Mail Removed)> wrote in message
news:376EE507-7B2B-49DB-B41F-(E-Mail Removed)...
> My macro imports a couple of csv files that are always located in the
> c:\users\username\documents\data folder, with username being the user whose
> computer the spreadsheet is being used on. Unfortunately for me, whenever I
> make a change to the macro, I have to create a separate copy for each
> individual so that the file path to the csv file that's being imported is
> correct. The portion of the code that refers to the file reads:
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;C:\Users\username\Documents\Data\Import.csv" _
> , Destination:=Range("A3"))
> .Name = "Import"
>
> Is there a way to code this so I don't have to change the path for each user?
>
> Thanks for any help.



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      19th Jul 2007
sorry, missed a backslash

fpath = "c:\users\" & Environ("username") & "\Documents\Data\"

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fpath & "Import.csv" _
, Destination:=Range("A3"))
.Name = "Import"


--


Gary


"Greg" <(E-Mail Removed)> wrote in message
news:376EE507-7B2B-49DB-B41F-(E-Mail Removed)...
> My macro imports a couple of csv files that are always located in the
> c:\users\username\documents\data folder, with username being the user whose
> computer the spreadsheet is being used on. Unfortunately for me, whenever I
> make a change to the macro, I have to create a separate copy for each
> individual so that the file path to the csv file that's being imported is
> correct. The portion of the code that refers to the file reads:
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;C:\Users\username\Documents\Data\Import.csv" _
> , Destination:=Range("A3"))
> .Name = "Import"
>
> Is there a way to code this so I don't have to change the path for each user?
>
> Thanks for any help.



 
Reply With Quote
 
=?Utf-8?B?R3JlZw==?=
Guest
Posts: n/a
 
      20th Jul 2007
That works great. Thanks.

One other complication. There may also be some users running Windows XP. In
this case, the file would be located at

C:\Documents and Settings\username\Documents\Data\Import.csv

Is there a way to code it so it can be used on both Windows XP & Vista
machines?

Thanks!

"Gary Keramidas" wrote:

> sorry, missed a backslash
>
> fpath = "c:\users\" & Environ("username") & "\Documents\Data\"
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;" & fpath & "Import.csv" _
> , Destination:=Range("A3"))
> .Name = "Import"
>
>
> --
>
>
> Gary
>
>
> "Greg" <(E-Mail Removed)> wrote in message
> news:376EE507-7B2B-49DB-B41F-(E-Mail Removed)...
> > My macro imports a couple of csv files that are always located in the
> > c:\users\username\documents\data folder, with username being the user whose
> > computer the spreadsheet is being used on. Unfortunately for me, whenever I
> > make a change to the macro, I have to create a separate copy for each
> > individual so that the file path to the csv file that's being imported is
> > correct. The portion of the code that refers to the file reads:
> >
> > With ActiveSheet.QueryTables.Add(Connection:= _
> > "TEXT;C:\Users\username\Documents\Data\Import.csv" _
> > , Destination:=Range("A3"))
> > .Name = "Import"
> >
> > Is there a way to code this so I don't have to change the path for each user?
> >
> > Thanks for any help.

>
>
>

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      20th Jul 2007
maybe this will work, or maybe someone has a vbscript.

Sub test()
If UCase(Split(Environ("homepath"), "\")(1)) = "USERS" Then
MsgBox "vista"
ElseIf UCase(Split(Environ("homepath"), "\")(1)) = "DOCUMENTS AND
SETTINGS" Then
MsgBox "XP"
Else
MsgBox "some other os"
End If
End Sub

--


Gary


"Greg" <(E-Mail Removed)> wrote in message
news:9BF5099C-99F0-4FD6-9783-(E-Mail Removed)...
> That works great. Thanks.
>
> One other complication. There may also be some users running Windows XP. In
> this case, the file would be located at
>
> C:\Documents and Settings\username\Documents\Data\Import.csv
>
> Is there a way to code it so it can be used on both Windows XP & Vista
> machines?
>
> Thanks!
>
> "Gary Keramidas" wrote:
>
>> sorry, missed a backslash
>>
>> fpath = "c:\users\" & Environ("username") & "\Documents\Data\"
>>
>> With ActiveSheet.QueryTables.Add(Connection:= _
>> "TEXT;" & fpath & "Import.csv" _
>> , Destination:=Range("A3"))
>> .Name = "Import"
>>
>>
>> --
>>
>>
>> Gary
>>
>>
>> "Greg" <(E-Mail Removed)> wrote in message
>> news:376EE507-7B2B-49DB-B41F-(E-Mail Removed)...
>> > My macro imports a couple of csv files that are always located in the
>> > c:\users\username\documents\data folder, with username being the user whose
>> > computer the spreadsheet is being used on. Unfortunately for me, whenever I
>> > make a change to the macro, I have to create a separate copy for each
>> > individual so that the file path to the csv file that's being imported is
>> > correct. The portion of the code that refers to the file reads:
>> >
>> > With ActiveSheet.QueryTables.Add(Connection:= _
>> > "TEXT;C:\Users\username\Documents\Data\Import.csv" _
>> > , Destination:=Range("A3"))
>> > .Name = "Import"
>> >
>> > Is there a way to code this so I don't have to change the path for each
>> > user?
>> >
>> > Thanks for any help.

>>
>>
>>



 
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
File Path and Name in Import String =?Utf-8?B?S2lyayBQLg==?= Microsoft Access VBA Modules 2 17th Feb 2006 02:22 PM
Need Current Path to import TXT file Birk Binnard Microsoft Access External Data 1 24th Aug 2005 08:52 PM
changing file path from d:\ to c:\ Jo Ann Microsoft Windows 2000 File System 2 5th Jul 2004 06:22 AM
Changing path of PST file Allaire Smith Microsoft Outlook Installation 1 14th Nov 2003 09:15 PM
changing path to AVI file CR Optiker Microsoft Powerpoint 2 7th Jul 2003 11:26 PM


Features
 

Advertising
 

Newsgroups
 


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