How to determine desktop directory ?

R

Robert

Hello !

Using a macro in excel, I want to save a folder as a csv file in the
desktop directory of the current user :

ActiveWorkbook.SaveAs Filename:= Filename, _
FileFormat:=xlCSV, _
CreateBackup:=False

The problem is to figure out which is the desktop directory of the user...

I cannot "build" myself the path using the login of the user because :
- I don't know on which disk it is
- I don't know which language was used at install time (Name of the
final directory in the full path of the desktop depends on it : Desktop
in English, Bureau in French, etc...)

Thanks for any advices !

R.
 
D

Dave Peterson

One way:

Option Explicit
Sub testme()

Dim WSHShell As Object
Dim DesktopPath As String

Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

MsgBox DesktopPath

End Sub
 
R

Robert

Dave said:
One way:

Option Explicit
Sub testme()

Dim WSHShell As Object
Dim DesktopPath As String

Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

MsgBox DesktopPath

End Sub

Thanks a lot Dave !
It works perfectly...

R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top