Help with VBA syntax

First: The results of the Wscript.Shell SpecialFolders method is going to be the complete path to the users desktop, which will include the drive letter, which may or may not be C:\, so you do not need to add it yourself.

Once you have the path you want to check assembled, you can simply use the FolderExists method of the FileSystemObject to see if the folder exists, and the CreateFolder method to create the new folder if needed.

https://msdn.microsoft.com/en-us/library/aa711216%28v=vs.71%29.aspx

Also, a useful debugging technique is to cause stuff like this that you are unsure of to print out, either using a MsgBox, or just as the return of a cell function. Then you can see for yourself if what you are trying is creating the right output.

Now, the code sample you started with compresses everything into one line, which is clever and compact, but not always the easiest to understand, or to reuse. The solution below separates the different steps, so it is hopefully easier to understand.

' Make containers for objects, the desktop path, and the new folder.
Dim Wsh As Object
Dim Fso as Obejct
Dim TestFolder as String
Dim TestPath As String

' Set the name of the new folder here
TestFolder = "Test"

' Create the Shell and FileSystem objects 
Set Wsh = CreateObject("WScript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")

' Construct the string that contains the new folder on the user desktop
TestPath = Wsh.SpecialFolders("Desktop") & TestFolder
MsgBox "TestPath = " & TestPath

' Test if the folder exists
If not Fso.FolderExists(TestPath) Then
    fso.CreateFolder(TestPath)
End If
DoSomething
/r/excel Thread