मुख्य सामग्री पर जाएं

 कैसे जांचें कि कोई फ़ोल्डर मौजूद है या नहीं और यदि नहीं है तो उसे कैसे बनाएं?

लेखक: ज़ियाओयांग अंतिम संशोधित: 2020-11-18

क्या आपने कभी यह जांचने का प्रयास किया है कि एक्सेल वर्कशीट में कोई फ़ोल्डर मौजूद है या नहीं? इस लेख में, मैं यह जांचने के बारे में बात करूंगा कि क्या कोई फ़ोल्डर निर्दिष्ट पथ में मौजूद है, यदि नहीं, तो पथ के तहत फ़ोल्डर स्वचालित रूप से बनाया जाएगा।

जांचें कि VBA कोड के साथ किसी विशिष्ट फ़ाइल पथ में कोई फ़ोल्डर मौजूद है या नहीं

यदि VBA कोड के साथ किसी विशिष्ट फ़ाइल पथ में मौजूद नहीं है तो फ़ोल्डर बनाएं


तीर नीला दायां बुलबुला जांचें कि VBA कोड के साथ किसी विशिष्ट फ़ाइल पथ में कोई फ़ोल्डर मौजूद है या नहीं

निम्नलिखित VBA कोड आपको यह जांचने में मदद कर सकता है कि क्या कोई फ़ोल्डर किसी विशिष्ट फ़ाइल पथ में मौजूद है, कृपया ऐसा करें:

1. दबाए रखें ALT + F11 कुंजी को खोलने के लिए अनुप्रयोगों के लिए माइक्रोसॉफ्ट विज़ुअल बेसिक खिड़की.

2। क्लिक करें सम्मिलित करें > मॉड्यूल, और निम्नलिखित कोड को इसमें पेस्ट करें मॉड्यूल खिड़की।

वीबीए कोड: जांचें कि क्या कोई फ़ोल्डर किसी विशिष्ट फ़ाइल पथ में मौजूद है:

Sub Test_Folder_Exist_With_Dir()
'Updateby Extendoffice
    Dim sFolderPath As String
    sFolderPath = "C:\Users\DT168\Desktop\Test folder"
    If Right(sFolderPath, 1) <> "\" Then
        sFolderPath = sFolderPath & "\"
    End If
    If Dir(sFolderPath, vbDirectory) <> vbNullString Then
        MsgBox "Folder exist", vbInformation, "Kutools for Excel"
    Else
        MsgBox "Folder doesn't exist", vbInformation, "Kutools for Excel"
    End If
End Sub

नोट: उपरोक्त कोड में, आपको फ़ोल्डर पथ और नाम बदलना चाहिए C:\Users\DT168\Desktop\Test फ़ोल्डर आपकी जरूरत के लिए.

3। फिर दबायें F5 इस कोड को चलाने के लिए कुंजी, आपको निम्नलिखित परिणाम मिलेंगे:

दस्तावेज़ फ़ोल्डर मौजूद 1


तीर नीला दायां बुलबुला यदि VBA कोड के साथ किसी विशिष्ट फ़ाइल पथ में मौजूद नहीं है तो फ़ोल्डर बनाएं

जांचें कि क्या फ़ाइल पथ में कोई फ़ोल्डर मौजूद है, यदि नहीं, तो इसे इस विशिष्ट फ़ाइल पथ के अंतर्गत बनाने के लिए, निम्नलिखित VBA कोड आपको इस कार्य को पूरा करने में मदद कर सकता है।

1. दबाए रखें ALT + F11 कुंजी को खोलने के लिए अनुप्रयोगों के लिए माइक्रोसॉफ्ट विज़ुअल बेसिक खिड़की.

2। क्लिक करें सम्मिलित करें > मॉड्यूल, और निम्नलिखित कोड को इसमें पेस्ट करें मॉड्यूल खिड़की।

वीबीए कोड: यदि फ़ाइल पथ में मौजूद नहीं है तो एक फ़ोल्डर बनाएं:

Sub MakeMyFolder()
'Updateby Extendoffice
    Dim fdObj As Object
    Application.ScreenUpdating = False
    Set fdObj = CreateObject("Scripting.FileSystemObject")
    If fdObj.FolderExists("C:\Users\DT168\Desktop\Test folder") Then
        MsgBox "Found it.", vbInformation, "Kutools for Excel"
    Else
        fdObj.CreateFolder ("C:\Users\DT168\Desktop\Test folder")
        MsgBox "It has been created.", vbInformation, "Kutools for Excel"
    End If
    Application.ScreenUpdating = True
End Sub

नोट: उपरोक्त कोड में, आपको फ़ोल्डर पथ और नाम बदलना चाहिए C:\Users\DT168\Desktop\Test फ़ोल्डर आपकी जरूरत के लिए.

3. - कोड पेस्ट करने के बाद प्रेस करें F5 इसे चलाने की कुंजी:

(1.) यदि फ़ोल्डर मौजूद है, तो दिखाए गए स्क्रीनशॉट के अनुसार एक प्रॉम्प्ट बॉक्स पॉप आउट हो जाएगा:

दस्तावेज़ फ़ोल्डर मौजूद 2

(2.) यदि फ़ोल्डर मौजूद नहीं है, तो इसे तुरंत विशिष्ट पथ के तहत बनाया जाएगा, और एक प्रॉम्प्ट बॉक्स आपको यह याद दिलाने के लिए पॉप आउट होगा कि फ़ोल्डर बनाया गया है, स्क्रीनशॉट देखें:

दस्तावेज़ फ़ोल्डर मौजूद 3

सर्वोत्तम कार्यालय उत्पादकता उपकरण

🤖 कुटूल्स एआई सहयोगी: निम्न के आधार पर डेटा विश्लेषण में क्रांति लाएं: बुद्धिमान निष्पादन   |  कोड जनरेट करें  |  कस्टम फ़ॉर्मूले बनाएं  |  डेटा का विश्लेषण करें और चार्ट बनाएं  |  कुटूल फ़ंक्शंस का आह्वान करें...
लोकप्रिय सुविधाएँ: डुप्लिकेट ढूंढें, हाइलाइट करें या पहचानें   |  रिक्त पंक्तियाँ हटाएँ   |  डेटा खोए बिना कॉलम या सेल को संयोजित करें   |   फॉर्मूला के बिना गोल ...
सुपर लुकअप: एकाधिक मानदंड VLookup    मल्टीपल वैल्यू वीलुकअप  |   अनेक शीटों में VLookup   |   फजी लुकअप ....
उन्नत ड्रॉप-डाउन सूची: शीघ्रता से ड्रॉप डाउन सूची बनाएं   |  आश्रित ड्रॉप डाउन सूची   |  बहु-चयन ड्रॉप डाउन सूची ....
स्तम्भ प्रबंधक: कॉलमों की एक विशिष्ट संख्या जोड़ें  |  कॉलम ले जाएँ  |  छिपे हुए कॉलम की दृश्यता स्थिति टॉगल करें  |  रेंज और कॉलम की तुलना करें ...
फीचर्ड फीचर्स: ग्रिड फोकस   |  डिजाइन देखें   |   बड़ा फॉर्मूला बार    कार्यपुस्तिका एवं शीट प्रबंधक   |  संसाधन लाइब्रेरी (ऑटो टेक्स्ट)   |  खजूर बीनने वाला   |  कार्यपत्रकों को संयोजित करें   |  एन्क्रिप्ट/डिक्रिप्ट सेल    सूची के अनुसार ईमेल भेजें   |  सुपर फ़िल्टर   |   विशेष फ़िल्टर (फ़िल्टर बोल्ड/इटैलिक/स्ट्राइकथ्रू...) ...
शीर्ष 15 टूलसेट12 टेक्स्ट टूल्स (पाठ जोड़ें, अक्षर हटाएँ, ...)   |   50 + चार्ट प्रकार (गैन्ट चार्ट, ...)   |   40+ प्रैक्टिकल सूत्र (जन्मदिन के आधार पर आयु की गणना करें, ...)   |   19 निवेशन टूल्स (QR कोड डालें, पथ से चित्र सम्मिलित करें, ...)   |   12 रूपांतरण टूल्स (शब्दों को संख्याएँ, मुद्रा रूपांतरण, ...)   |   7 विलय और विभाजन टूल्स (उन्नत संयोजन पंक्तियाँ, विभाजन कोशिकाओं, ...)   |   ... और अधिक

एक्सेल के लिए कुटूल के साथ अपने एक्सेल कौशल को सुपरचार्ज करें, और पहले जैसी दक्षता का अनुभव करें। एक्सेल के लिए कुटूल उत्पादकता बढ़ाने और समय बचाने के लिए 300 से अधिक उन्नत सुविधाएँ प्रदान करता है।  वह सुविधा प्राप्त करने के लिए यहां क्लिक करें जिसकी आपको सबसे अधिक आवश्यकता है...

Description


ऑफिस टैब ऑफिस में टैब्ड इंटरफ़ेस लाता है, और आपके काम को बहुत आसान बनाता है

  • Word, Excel, PowerPoint में टैब्ड संपादन और रीडिंग सक्षम करें, प्रकाशक, एक्सेस, विसियो और प्रोजेक्ट।
  • नई विंडो के बजाय एक ही विंडो के नए टैब में एकाधिक दस्तावेज़ खोलें और बनाएं।
  • आपकी उत्पादकता 50% बढ़ जाती है, और आपके लिए हर दिन सैकड़ों माउस क्लिक कम हो जाते हैं!
Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Buonasera,

Non conosco il Vs. sito e mi sono imbattuto per caso su questa pagina.
Ho letto quanto scritto sopra e se è possibile avrei bisogno del Vs. aiuto.
Mi occorrerebbe una macro che in un percorso variabile ad un Host facente parte della stessa lan verifiche se è aperto un file exel dal nome variabile, e nel caso sia aperto chiuda il file e cancella tutto il contenuto della cartella compreso il file stesso.
Provo a spiegarmi meglio:
nel percorso :\\host01\Users\utente\Desktop\liste\Nome_Cognome_Gennaio\Operatore_16_Gennaio.xlsm
è presente un file excel dal nome : Operatore_16_Gennaio.xlsm

Il percorso non sempre è lo stesso così come il nome del file excel. Infatti il percorso cambia solo nel Nome_Cognome,es: :\\host01\Users\utente\Desktop\liste\Tizio_Caio_Gennaio\Operatore_16_Gennaio.xlsm) mentre nel file cambia solo il numero dell'operatore (Es: :\\host01\Users\utente\Desktop\liste\Sempronio_zeta_Gennaio\Operatore_15_Gennaio.xlsm.)

E' possibile avere una macro che fa quanto descritto sopra?

Ringrazio anticipatamente
This comment was minimized by the moderator on the site
How to create folder in desktop with vba whenever the excel book is opened, if exist, ignore.
Message if create new folder, silent if the folder exist.

Private Sub Workbook_Open()

Dim cOb As Variant
Dim FolderName As String, FolderExists As String
FolderName = "C:\Users\" & Environ("username") & "\Desktop\MyFolder\" '--->Change folder name to suit.
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") & "\" & "MyFolder" '--->Change folder name to suit.
MkDir cOb
Else: Exit Sub
End If

Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
How to create folder in desktop with vba whenever the excel book is opened, if exist, ignore.
Message if create new folder, silent if the folder exist.


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

This comment was minimized by the moderator on the site
excelente, me sirvió mucho el Objeto. Uso para carpetas como archivos. Muchas gracias
This comment was minimized by the moderator on the site
Hi, This works great, would there be any chance that the folder name used when checking if a folder already exists is derived from a cell within the spreadsheet, say A2??

I use a template spreadsheet which is updated automatically from another source, so cell A2 constantly changes which requires new folders being created in the same name.

Also, could there be such a command which does the above but also saves the active spreadsheet in the found / created folder?

Any hope? TIA
This comment was minimized by the moderator on the site
I'm running this macro, but in the step to create the folder, the process goes down.

can you help me????


'Comprobar si la carpeta existe

Dim ruta As String
Dim libro As String

M = ActiveWorkbook.Name

ruta = Application.Workbooks(M).Sheets("Diccionario").Range("B5").Value

If Right(ruta, 1) <> "\" Then
ruta = ruta & "\"
End If
If Dir(ruta, vbDirectory) <> vbNullString Then
MsgBox "Folder exist, please continue"
Else
MsgBox "Folder doesn't exist"
End If

'Crea la carpeta que necesitas

Dim fdObj As Object
Dim folder As String

folder = Application.Workbooks(M).Sheets("Dicionario").Range("B5").Value (here is where the process falls)

Application.ScreenUpdating = False
Set fdObj = CreateObject("Scripting.FileSystemObject")
If fdObj.FolderExists(folder) Then
MsgBox "Found it, pleace continue."
Else
fdObj.CreateFolder (folder)
MsgBox "It has been created."
End If
Application.ScreenUpdating = True
This comment was minimized by the moderator on the site
Super Thanks!
This comment was minimized by the moderator on the site
Thanks Man, work amazing
This comment was minimized by the moderator on the site
This is really helpful! thanks!
This comment was minimized by the moderator on the site
Great article. Just what I was looking for :)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations