Create folder in desktop with vba, if exist, ignore
Solved/Closed
viriato74
Posts
4
Registration date
Friday August 20, 2021
Status
Member
Last seen
August 21, 2021
-
Aug 20, 2021 at 10:29 PM
praveen - Aug 12, 2023 at 04:03 PM
praveen - Aug 12, 2023 at 04:03 PM
Related:
- Vba create folder if not exist
- Excel vba create folder if not exist - Best answers
- Vba create folder if not exists - Best answers
- Anvi folder locker reset key - Guide
- Create skype account with gmail - Guide
- To create a network bridge you must ✓ - Network Forum
- Vba case like - Guide
- Steam screenshot folder - Guide
2 responses
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
Updated on Aug 21, 2021 at 11:18 AM
Updated on Aug 21, 2021 at 11:18 AM
Hello Viriato,
The following VBA code should work for you:-
It will create a folder on your desktop named "A New Folder" with a message box warning. As it will exist thereafter, nothing else will happen each time your workbook is opened thereafter.
To implement this code:-
- Right click on any sheet tab.
- Select "View Code" from the menu that appears.
- In the Project Explorer which then appears, over to the left, double click on "ThisWorkbook".
- Over to the right in the big white code field, paste the above code.
You will need to change the folder path to suit your requirements.
I hope that this helps.
Cheerio,
vcoolio.
The following VBA code should work for you:-
Private Sub Workbook_Open() Dim cOb As Variant Dim FolderName As String, FolderExists As String FolderName = "C:\Users\AAAAA\Desktop\A New Folder" '---->Change folder name to suit. Change the AAAAA to your requirement. FolderExists = Dir(FolderName, vbDirectory) Application.ScreenUpdating = False If FolderExists = vbNullString Then MsgBox "The desktop folder doesn't exist. Creating a new folder now.", vbExclamation, "INFORMATION" cOb = CreateObject("wscript.shell").specialfolders("Desktop") & "\" & "A New Folder" '--->Change folder name to suit. MkDir cOb Else: Exit Sub End If Application.ScreenUpdating = True End Sub
It will create a folder on your desktop named "A New Folder" with a message box warning. As it will exist thereafter, nothing else will happen each time your workbook is opened thereafter.
To implement this code:-
- Right click on any sheet tab.
- Select "View Code" from the menu that appears.
- In the Project Explorer which then appears, over to the left, double click on "ThisWorkbook".
- Over to the right in the big white code field, paste the above code.
You will need to change the folder path to suit your requirements.
I hope that this helps.
Cheerio,
vcoolio.
Aug 21, 2021 at 11:58 AM
Thank you so much for your help.
Aug 12, 2023 at 04:03 PM
is there any code to pick the shared path from excel FolderName = "C:\Users\AAAAA\Desktop\A New Folder" ' FolderName =Sheets("Sheet1").Range("a1")