How to determine desktop directory ?

  • Thread starter Thread starter Robert
  • Start date Start date
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.
 
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
 
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.
 
Back
Top