'********************************************************************************************************** ' Name: getDesktopPath ' Author: mielk | 2014-12-11 ' ' Comment: Function returns the path to the Desktop folder. ' ' Returns: ' String The full access path to the Desktop folder. ' ' ' Exceptions: ' CreatingObjectException Thrown if it was impossible to create an instance of WScript.Shell ' object. ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2014-12-11 mielk Function created. '********************************************************************************************************** Public Function getDesktopPath() As String Const METHOD_NAME As String = "getDesktopPath" '------------------------------------------------------------------------------------------------------ Const LIBRARY_NAME As String = "WScript.Shell" Const DESKTOP_FOLDER_ALIAS As String = "Desktop" '------------------------------------------------------------------------------------------------------ Dim shell As Object '------------------------------------------------------------------------------------------------------ 'Create a new instance of WScript.Shell object ------------------------------------------------------| On Error GoTo CreatingObjectException '| Set shell = VBA.CreateObject(LIBRARY_NAME) '| On Error GoTo 0 '| '----------------------------------------------------------------------------------------------------| 'If shell object has been properly created, use it to obtain Desktop folder path. -------------------| If Not shell Is Nothing Then '| getDesktopPath = shell.SpecialFolders(DESKTOP_FOLDER_ALIAS) '| End If '| '----------------------------------------------------------------------------------------------------| '========================================================================================================== ExitPoint: Set shell = Nothing Exit Function '---------------------------------------------------------------------------------------------------------- CreatingObjectException: 'Error handler for the case if it was impossible to create an instance of Scriptlet.TypeLib object. GoTo ExitPoint End Function