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

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.misc
external usenet poster
 
Posts: 1,805
Default Generic file path Excel Macro Question

ThisWorkBook.Path will give you the path of the file containing the macro.

You can use that to get the path if you place it on the Desktop.

"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.misc
external usenet poster
 
Posts: 11,501
Default Generic file path Excel Macro Question

Hi,

Try this

Sub GetDesktop()
Dim desktop As String
Set objWSHShell = CreateObject("WScript.Shell")
desktop = objWSHShell.SpecialFolders("Desktop")
Workbooks.Open desktop & "\" & "Data_Export.xls"
End Sub

Mike
"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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 41
Default Generic file path Excel Macro Question

Maybe I wasn't specific enough. The macro is going out to the desktop and
opening an excel file(no macro in this excel file), copying a specific sheet,
pasting into the excel file where the macro is being ran, and closing the
desktop file.

My problem is this macro is being ran on different pc's, and instead
renaming the file path in the macro for each individual pc, i was wondering
if there was a generic word or phrase you can use for the username portion of
the file path going to the desktop.

"Sheeloo" wrote:

ThisWorkBook.Path will give you the path of the file containing the macro.

You can use that to get the path if you place it on the Desktop.

"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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default Generic file path Excel Macro Question

I had understood the problem. I thought you would be able to put the file
with the macro at the desktop or below it...

Mike has given the generic solution...

"dwake" wrote:

Maybe I wasn't specific enough. The macro is going out to the desktop and
opening an excel file(no macro in this excel file), copying a specific sheet,
pasting into the excel file where the macro is being ran, and closing the
desktop file.

My problem is this macro is being ran on different pc's, and instead
renaming the file path in the macro for each individual pc, i was wondering
if there was a generic word or phrase you can use for the username portion of
the file path going to the desktop.

"Sheeloo" wrote:

ThisWorkBook.Path will give you the path of the file containing the macro.

You can use that to get the path if you place it on the Desktop.

"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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 41
Default Generic file path Excel Macro Question

Worked perfect Mike. Much appreciated.

"Mike H" wrote:

Hi,

Try this

Sub GetDesktop()
Dim desktop As String
Set objWSHShell = CreateObject("WScript.Shell")
desktop = objWSHShell.SpecialFolders("Desktop")
Workbooks.Open desktop & "\" & "Data_Export.xls"
End Sub

Mike
"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
Generic reference in a Macro Harry's GMail World Excel Discussion (Misc queries) 2 April 17th 07 11:07 PM
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
Macro help: File path in Excel 2000 macronewfie Excel Discussion (Misc queries) 2 May 26th 06 02:21 PM
Creation of a Generic Macro Sondra Excel Worksheet Functions 1 September 13th 05 10:40 PM
Macro - Feeding path and file name to PDF maker Bill Excel Discussion (Misc queries) 1 July 21st 05 03:39 PM


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

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

About Us

"It's about Microsoft Excel"