Dileep,
You need to use Windows API calls to find the Desktop folder for the current
user. I have code on my website that handles all this for you, not just for
the Desktop folder but all special folders like History, Favorites, and
MyDocuments. You just pass in an identifier indicating which special folder
you want, and the function return the correct full folder name.
See
http://www.cpearson.com/excel/SpecialFolders.htm for example code.
Download and import the code module
http://www.cpearson.com/Zips/modGetUserDirectory.zip
from that page into your project, and then use code like the following to
get the folder to the user's desktop:
Function GetDeskTopFolder() As String
''''''''''''''''''''''''''''''''''''''
' GetDeskTopFolder
' Returns the folder of the desktop
' for the current user.
''''''''''''''''''''''''''''''''''''''
Dim CSIDL As Long
CSIDL = CSIDL_DESKTOP
GetDeskTopFolder = F_7_AB_1_GetSpecialFolder(CSIDL_DESKTOP)
End Function
This function will return the path of the user's desktop folder. You can
then use that function in code like the following:
Sub OpenFileOnDesktop()
Dim DesktopFolder As String
Dim FName As String
Dim WB As Workbook
FName = "Test.xls" '<<<< CHANGE AS NEEDED
DesktopFolder = GetDeskTopFolder()
Set WB = Workbooks.Open(DesktopFolder & "\" & FName)
Debug.Print WB.FullName
End Sub
Sub SaveToDesktop()
Dim DesktopFolder As String
Dim FName As String
Dim WB As Workbook
FName = "Test.xls" '<<<< CHANGE AS NEEDED
DesktopFolder = GetDeskTopFolder()
ActiveWorkbook.SaveAs DesktopFolder & "\" & FName
Debug.Print ActiveWorkbook.FullName
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)