Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Generic file path using vba

I have a vba code that opens a file placed on my desktop, but this vba code
must be used in several pc's, and in every pc the desktop path is different
due to different user names.

I would like to now if it's possible to write a "generic" path for the vba
to find the files with no matter which of the pc desktops the macro is being
ran at. The files will be placed always in the desktop folder.

here is the string I am using to open the file.
Workbooks.Open "C:\Documents and Settings\[Username]\Desktop\Data_Export.xls"

Any advice would be appreciated


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Generic file path using vba

No need for another thread, you have an answer in the other one in general
questions

"dwake" wrote:

I have a vba code that opens a file placed on my desktop, but this vba code
must be used in several pc's, and in every pc the desktop path is different
due to different user names.

I would like to now if it's possible to write a "generic" path for the vba
to find the files with no matter which of the pc desktops the macro is being
ran at. The files will be placed always in the desktop folder.

here is the string I am using to open the file.
Workbooks.Open "C:\Documents and Settings\[Username]\Desktop\Data_Export.xls"

Any advice would be appreciated


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Generic file path using vba


At http://www.cpearson.com/Excel/SpecialFolders.aspx I have a module
you can import into your project that allows you to get the actual
path locations of about 50 predefined directories associated with a
user (e.g,. Desktop, My Documents, Favorites, My Music, etc). Download
the file from the page above, unzip it into some folder (it doesn't
matter what folder), and then in VBA, go to the File menu, choose
Import File, and select the bas file you just unzipped. That module
has constant names for all the files (e.g., CSIDL_DESKTOP = &H0) and a
function named GetSpecialFolder that will take a CSIDL value and
return the folder name. E.g.,

Dim S As String
S = GetSpecialFolder(CSIDL_DESKTOPDIRECTORY)
Debug.Print S

which on my machine is "C:\Users\Pearson\Desktop".

No modifications are required to the imported module. Just call the
GetSpecialFolder function passing it the appropriate CSIDL value, all
of which are constants in the imported file.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 27 Jan 2009 13:40:01 -0800, dwake
wrote:

I have a vba code that opens a file placed on my desktop, but this vba code
must be used in several pc's, and in every pc the desktop path is different
due to different user names.

I would like to now if it's possible to write a "generic" path for the vba
to find the files with no matter which of the pc desktops the macro is being
ran at. The files will be placed always in the desktop folder.

here is the string I am using to open the file.
Workbooks.Open "C:\Documents and Settings\[Username]\Desktop\Data_Export.xls"

Any advice would be appreciated

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Path Too Long? Not Anymore! Check out Long Path Tool Max Loger Excel Discussion (Misc queries) 1 March 24th 17 07:59 AM
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Generic file path Excel Macro Question dwake Excel Discussion (Misc queries) 5 January 28th 09 06:09 AM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
check if file with generic name already open Spike Excel Programming 2 November 25th 05 11:03 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"