【VBA】Get path to the Desktop

You can get
path to the Desktop”!

Use “SpecialFolders property” of “WScript.Shell object“!

PR

VBA Code

You can get “path to the Desktop” by “SpecialFolders property” of “WScript.Shell object“.

Option Explicit

Sub sampleProc()

    Dim wsh As Object
    
    'Get "WScript.Shell object"
    Set wsh = CreateObject("WScript.Shell")

    'Get "path to the Desktop"
    MsgBox wsh.SpecialFolders("Desktop")

    Set wsh = Nothing
    
End Sub

Set “Desktop” to “SpecialFolders property“(Line 11).

PR

Result

You got “path to the Desktop”!

path to the Desktop
path to the Desktop
PR

FYI No.1

Also, you can get “User Name”.

For more information, see the following article:

PR

FYI No.2

Also, you can get “Computer Name”.

For more information, see the following article:

タイトルとURLをコピーしました