Check for desktop folder

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
569
Office Version
  1. 365
Platform
  1. Windows
I want to have a macro that will check for a specific folder on the desktop of the user that is using the file. Because the file is being used by several different users, I cannot use a specific file path as the users name in the file path will vary depending on who is using the file. The macro should do the following:

1) If there is NOT a folder named "Active Jobs" on the desktop
2) Ask the user if they would like to create one
3) If the user answers "YES"
4) Create new folder on the desktop named "Active Jobs"
5) Inform user a folder named "Active Jobs" now exists on the desktop
6) If "NO" - no folder is created and exit sub.
7) If a folder is found,
8) Display a message box to confirm "Active Jobs" folder already exists.

Any support with this would be much appreciated. I have been searching online and am a little confused on how to correctly get this done.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi rjplante,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    If Dir("C:\Users\" & Environ("USERNAME") & "\Desktop\Active Jobs", vbDirectory) = "" Then
        If MsgBox("There is no folder in your desktop called ""Active Jobs""." & vbNewLine & "Would you like to create it?", vbYesNo) = vbNo Then
            Exit Sub
        Else
            'Can just create the folder as it's assumed
            'C:\Users\" & Environ("USERNAME") & "\Desktop\' resides on all machines
            MkDir "C:\Users\" & Environ("USERNAME") & "\Desktop\Active Jobs"
            MsgBox "The folder ""Active Jobs"" now exists on your desktop."
        End If
    Else
        MsgBox "The folder ""Active Jobs"" already exists."
    End If

End Sub

Regards,

Robert
 
Upvote 0
Another option....

VBA Code:
Sub MsgboxDesktopAddress()
    MsgBox CreateObject("WScript.Shell").SpecialFolders("Desktop")
End Sub
 
Upvote 0
Nice MARK858 (y)

rjplante - I would use MARK858's solution as it's more dynamic to find the location of the desktop folder so:

VBA Code:
Option Explicit
Sub Macro2()

    If Dir(CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Active Jobs", vbDirectory) = "" Then
        If MsgBox("There is no folder in your desktop called ""Active Jobs""." & vbNewLine & "Would you like to create it?", vbYesNo) = vbNo Then
            Exit Sub
        Else
            'Can just create the folder as it's assumed
            'C:\Users\" & Environ("USERNAME") & "\Desktop\' resides on all machines
            MkDir CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Active Jobs"
            MsgBox "The folder ""Active Jobs"" now exists on your desktop."
        End If
    Else
        MsgBox "The folder ""Active Jobs"" already exists."
    End If

End Sub

Regards,

Robert
 
Upvote 0
Thanks for the feedback gentlemen. The macro works awesome.
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top