Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Using VBA, what is a good way to obtain the path to the
user's current Windows 7 desktop? Once I have the path, I would like to be copy a few files or shortcuts onto the user's desktop. Thanks in advance. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Robert,
Am Thu, 14 Mar 2013 10:14:50 -0700 schrieb Robert Crandal: Using VBA, what is a good way to obtain the path to the user's current Windows 7 desktop? Once I have the path, I would like to be copy a few files or shortcuts onto the user's desktop. try: myPath = "C:\Users\" & Environ("UserName") & "\Desktop\" or select in Windows explorer the desktop, press Shift + right click = "Copy as path" and paste it in your module Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Robert Crandal wrote:
Using VBA, what is a good way to obtain the path to the user's current Windows 7 desktop? Once I have the path, I would like to be copy a few files or shortcuts onto the user's desktop. Thanks in advance. in 99%, you will find it he environ("USERPROFILE")+"\desktop" the other 1% is when desktop is redirected to other location. There is no environment variable pointing to desktop directly probably it can be found somewhere in windows settings but I do not know how. Also be careful when concatenating folders. on my computer, environ("USERPROFILE") does not have slash sign at the end, but some other variables does. it is better to use Microsoft Scripting Runtime library and FileSystemObject class from it to concatenate folders and check if destination exists. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Robert Crandal wrote:
Using VBA, what is a good way to obtain the path to the user's current Windows 7 desktop? Once I have the path, I would like to be copy a few files or shortcuts onto the user's desktop. While you usually *can* find it using the already-suggested USERPROFILE environment variable, or the FileSystemObject, the method I've found to be "best" (most reliable, whatever) is the SHGetSpecialFolderPath API call: Declare Function SHGetSpecialFolderPath Lib "SHELL32" _ Alias "SHGetSpecialFolderPathA" ( _ ByVal hwndOwner As Long, ByVal lpszPath As String, _ ByVal nFolder As Long, ByVal fCreate As Long) As Long Public Const MAX_PATH = 260 Public Const CSIDL_DESKTOPDIRECTORY = 16& Function whereIsDesktop() As String desktop$ = Space$(MAX_PATH + 1) result& = SHGetSpecialFolderPath(0, desktop$, CSIDL_DESKTOPDIRECTORY, 0) tmp& = InStr(desktop$, Chr$(0)) If tmp& Then desktop$ = Left$(desktop$, tmp& - 1) whereIsDesktop = desktop$ End Function Of course, this *probably* won't work if the path contains multi-byte characters of any kind. (Not a problem for most English-language installs.) (I use this because I usually change the location of the desktop to a certain directory on my server. Good luck getting something in C:\users\Auric\Desktop to show up on my desktop.) -- He's the friend who'll listen, although you may wish he hadn't. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Auric__" wrote :
While you usually *can* find it using the already-suggested USERPROFILE environment variable, or the FileSystemObject, the method I've found to be "best" (most reliable, whatever) is the SHGetSpecialFolderPath API call: ........ (I use this because I usually change the location of the desktop to a certain directory on my server. Good luck getting something in C:\users\Auric\Desktop to show up on my desktop.) First, thank you everyone who replied. All info was helpful..... And, BTW Auric, each user is assigned a directory on the server. I believe that each user has a Desktop either on the C: drive or a server directory named \\fserver1 or something similar. I don't remember exactly, but I will have to check. I will give this SHGetSpecialFolderPath() API next time I go to work. Seems odd that USERPROFILE and FileSystemObject and SHGetSpecialFolderPath() would return different results, but I shall put this to the test. Thanks again. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Robert Crandal wrote:
"Auric__" wrote : While you usually *can* find it using the already-suggested USERPROFILE environment variable, or the FileSystemObject, the method I've found to be "best" (most reliable, whatever) is the SHGetSpecialFolderPath API call: ........ (I use this because I usually change the location of the desktop to a certain directory on my server. Good luck getting something in C:\users\Auric\Desktop to show up on my desktop.) First, thank you everyone who replied. All info was helpful..... And, BTW Auric, each user is assigned a directory on the server. I believe that each user has a Desktop either on the C: drive or a server directory named \\fserver1 or something similar. I don't remember exactly, but I will have to check. I will give this SHGetSpecialFolderPath() API next time I go to work. Seems odd that USERPROFILE and FileSystemObject and SHGetSpecialFolderPath() would return different results, but I shall put this to the test. Thanks again. I tested SHGetSpecialFolderPath and it worked great pointing to right folder. I have desktops redirected to another disk separately from userprofile and it returned correct folder. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Desktop path? | Excel Programming | |||
Remove end folder from path found with ThisWorkbook.Path command ? | Excel Programming | |||
EXCEL FILES SAVED TO DESKTOP WILL NOT OPEN FROM DESKTOP | Excel Discussion (Misc queries) | |||
How to path to user's desktop | Excel Programming | |||
hyperlink navigation path path wrong in Excel 2003 | Excel Discussion (Misc queries) |