Create folder in desktop with vba, if exist, ignore
Solved/Closed
viriato74
Posts
4
Registration date
Friday 20 August 2021
Status
Member
Last seen
21 August 2021
-
20 Aug 2021 à 22:29
praveen - 12 Aug 2023 à 16:03
praveen - 12 Aug 2023 à 16:03
Related:
- Vba create folder if not exist
- Excel vba create folder if not exist - Best answers
- Vba create folder if not exists - Best answers
- Create new sheet vba - Guide
- Anvi folder locker reset key - Guide
- Vba find - Guide
- Create folder android - Guide
- Chrome extensions folder - Guide
2 responses
vcoolio
Posts
1411
Registration date
Thursday 24 July 2014
Status
Contributor
Last seen
6 September 2024
262
21 Aug 2021 à 11:13
21 Aug 2021 à 11:13
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.
21 Aug 2021 à 11:58
Thank you so much for your help.
12 Aug 2023 à 16:03
is there any code to pick the shared path from excel FolderName = "C:\Users\AAAAA\Desktop\A New Folder" ' FolderName =Sheets("Sheet1").Range("a1")