Loncat ke daftar isi utama

Buat beberapa folder dan subfolder dari daftar data di Excel

Pengarang: Xiaoyang Terakhir Dimodifikasi: 2024-03-01

Misalkan Anda memiliki daftar nama staf dalam rentang lembar kerja dan bertujuan untuk membuat folder individual untuk masing-masing folder guna menyimpan informasinya. Membuat setiap folder secara manual dapat memakan waktu. Namun, ada metode efisien untuk mempercepat proses ini. Dalam panduan ini, saya akan membagikan beberapa pendekatan untuk membuat folder dengan cepat berdasarkan nilai sel yang ditentukan.

Buat folder berdasarkan nilai sel

Buat folder dan subfolder berdasarkan nilai sel dengan kode VBA


Buat folder berdasarkan nilai sel

Di bagian ini, kita akan menjelajahi berbagai metode secara mendetail, menawarkan petunjuk langkah demi langkah yang komprehensif untuk membuat folder dengan cepat dan mudah berdasarkan daftar nilai sel.

Buat folder dari daftar dengan menggunakan perintah MD dan Notepad

Mengubah daftar dari Excel ke dalam folder menggunakan perintah MD dan Notepad adalah trik cerdas yang menggabungkan skrip batch yang mudah dengan kemampuan Excel untuk menjaga segala sesuatunya tetap teratur. Cara ini sangat bagus untuk membuat banyak folder dengan cepat, tanpa harus melakukan semuanya dengan tangan. Berikut panduan langkah demi langkah untuk menyelesaikan tugas ini:

Langkah 1: Gunakan perintah MD untuk membuat rumus

Salin atau masukkan rumus berikut ke dalam sel kosong di samping nilai sel pertama Anda (B1, misalnya), lalu, seret gagang isian ke bawah untuk menerapkan rumus ke semua item daftar Anda.

="MD "&A1

Langkah 2: Salin dan tempel rumus ke dalam file Notepad

  1. Tekan Ctrl + C untuk menyalin sel dengan rumus perintah MD.
  2. Open Notepad dan tekan Ctrl + V untuk menempelkan perintah ke file baru.

Langkah 3: Simpan file Notepad sebagai file .bat

Klik Simpan sebagai dari File tab di Notepad, di Simpan sebagai kotak dialog, pilih direktori tempat Anda ingin membuat beberapa folder, lalu beri nama untuk file ini dengan a Bat. perpanjangan. Terakhir, klik Save tombol. Lihat tangkapan layar:

Langkah 4: Klik dua kali file .bat untuk menghasilkan banyak folder

  1. Tutup file Notepad, arahkan ke folder tempat Anda sebelumnya menyimpan file .bat.
  2. Sekarang, saksikan keajaibannya: klik dua kali pada file tersebut, dan Anda akan melihat beberapa folder dibuat sekaligus. Lihat demonya di bawah ini:
 

Buat folder dari daftar dengan menggunakan alat canggih – Kutools for Excel

Dengan yang kuat Kutools untuk Excel'S Buat Folder dari Isi Sel fitur, kini Anda dapat dengan mudah dan cepat membuat folder dari daftar Excel. Namun hal ini tidak berhenti pada folder dasar saja; Kutools juga memungkinkan Anda membuat struktur kompleks dengan subfolder bertingkat sekaligus. Hanya beberapa langkah sederhana yang dapat mengubah data dari Excel menjadi sistem folder terorganisir, sehingga meningkatkan produktivitas Anda secara signifikan.

Note: Jika Anda ingin menggunakan ini Buat Folder dari Isi Sel fitur, silakan unduh dan instal Kutools untuk Excel pertama.

Setelah menginstal Kutools untuk Excel, Silakan klik Kutools Ditambah > Ekspor Impor > Buat Folder dari Isi Sel untuk membuka Buat Folder dari Isi Sel kotak dialog:

  1. Pilih nilai sel yang ingin Anda buatkan folder berdasarkan;
  2. Kemudian, klik tombol untuk menentukan folder tujuan Anda ingin menyimpan folder;
  3. Akhirnya, klik OK .

Hasil:

Kutools akan memproses daftar dari lembar Anda dan membuat folder untuk setiap entri di tujuan yang ditentukan. Arahkan ke folder tujuan untuk melihat hasilnya. Lihat tangkapan layar:

Tip:
  1. Fitur berguna ini juga dapat membantu membuat folder beserta subfoldernya sesuai kebutuhan Anda. Untuk melakukan ini, Anda harus memasukkan nama folder dan subfolder yang diinginkan ke dalam sel, menggunakan tanda garis miring terbalik (\) untuk memisahkan setiap level. Isi setiap sel akan bertindak sebagai panduan untuk mengatur struktur folder dan subfolder yang diinginkan.

    Kemudian, terapkan Buat Folder dari Isi Sel fitur, semua folder beserta subfoldernya akan berhasil dibuat. Lihat tangkapan layar:
  2. Untuk menerapkan fitur ini, silakan unduh dan instal Kutools untuk Excel pertama.
 

Buat folder dari daftar dengan menggunakan kode VBA

Menggunakan kode VBA di Excel dapat mengubah tugas membosankan membuat folder dari daftar menjadi proses yang cepat dan otomatis. Bagian ini akan menunjukkan cara menerapkan kode VBA untuk menghasilkan folder.

Langkah 1: Buka editor modul VBA dan salin kodenya

  1. Tahan ALT + F11 kunci di Excel, dan itu membuka file Microsoft Visual Basic untuk Aplikasi jendela.
  2. Klik Menyisipkan > Modul, dan tempel kode berikut di Modul Jendela.
    Kode VBA: Membuat folder berdasarkan daftar nilai sel
    Sub CreateFoldersFromSelection()
    'Updateby Extendoffice
        Dim FolderPath As String
        Dim Cell As Range
        Dim SelectedRange As Range
        Dim FolderName As String
        On Error Resume Next
        Set SelectedRange = Application.InputBox("Select the range with folder names", "Kutools for Excel", Type:=8)
        If SelectedRange Is Nothing Then Exit Sub
        On Error GoTo 0
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .Title = "Select the destination Folder"
            .AllowMultiSelect = False
            If .Show <> -1 Then Exit Sub
            FolderPath = .SelectedItems(1) & "\"
        End With
        
        For Each Cell In SelectedRange
            FolderName = FolderPath & Cell.Value
            If Cell.Value <> "" And Not FolderExists(FolderName) Then
                MkDir FolderName
            End If
        Next Cell
    End Sub
    
    Function FolderExists(ByVal Path As String) As Boolean
        On Error Resume Next
        FolderExists = (GetAttr(Path) And vbDirectory) = vbDirectory
        On Error GoTo 0
    End Function
    

Langkah 2: Jalankan kodenya

  1. Setelah menempelkan kode ini, harap tekan F5 kunci untuk menjalankan kode ini. Di kotak prompt, pilih nilai sel yang ingin Anda buat foldernya. Lalu, klik OK.
  2. Lalu, berikut ini Pilih Folder tujuan jendela, tentukan jalur tujuan untuk menampilkan folder yang dibuat. Lalu, klik OK tombol, lihat tangkapan layar:

Hasil:

Setelah menjalankan kode VBA, buka direktori tujuan untuk melihat hasilnya. Di sana, Anda akan menemukan folder yang baru dibuat, masing-masing terkait dengan item dari daftar Excel Anda. lihat tangkapan layar:

Tip:
  1. Jika ada entri duplikat di dalam sel, menjalankan kode akan menghasilkan hanya satu folder yang dibuat untuk duplikat tersebut.
  2. Jika Anda sering menggunakan kode ini, pertimbangkan untuk menyimpan buku kerja Anda Buku kerja Excel yang Diaktifkan Makro format. Tindakan ini mempertahankan kode di dalam buku kerja, memungkinkan Anda mengeksekusinya secara langsung di masa mendatang tanpa perlu memasukkan ulang atau mengimpor ulang kode tersebut.

Buat folder dan subfolder berdasarkan nilai sel dengan kode VBA

Kadang-kadang, Anda mungkin menemukan diri Anda dalam situasi di mana Anda perlu membuat tidak hanya folder, tetapi juga subfoldernya yang sesuai, semuanya berdasarkan data dalam sel Excel. Untuk mencapai tugas ini, di sini saya akan memperkenalkan kode VBA.

Langkah 1: Siapkan data

Pertama, Anda harus memasukkan data seperti gambar berikut, letakkan nama folder utama di kolom pertama dan nama subfolder di kolom kedua.

Langkah 2: Buka editor modul VBA dan salin kodenya

  1. Tahan ALT + F11 kunci di Excel, dan itu membuka file Microsoft Visual Basic untuk Aplikasi jendela.
  2. Klik Menyisipkan > Modul, dan tempel kode berikut di Modul Jendela.
    Kode VBA: Membuat folder dan subfolder berdasarkan nilai sel
    Sub CreateFoldersAndSubfoldersWithUserInput()
    'Updateby Extendoffice
        Dim Rng As Range
        Dim Cell As Range
        Dim basePath As String
        Dim fldrPicker As FileDialog
        Dim FolderPath As String, subfolderPath As String
        On Error Resume Next
        Set Rng = Application.InputBox("Select the range of cells (two columns: one is folder column, another s subfolder column):", "Kutools for Excel", Type:=8)
        If Rng Is Nothing Then Exit Sub
        On Error GoTo 0
        Set fldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
        With fldrPicker
            .Title = "Select the Base Folder Path"
            .AllowMultiSelect = False
            If .Show <> -1 Then Exit Sub
            basePath = .SelectedItems(1)
        End With
        If Right(basePath, 1) <> "\" Then basePath = basePath & "\"
        For Each Cell In Rng.Columns(1).Cells
            If Not Cell.Value = "" Then
                FolderPath = basePath & Cell.Value
                If Not FolderExists(FolderPath) Then MkDir FolderPath
                If Not Cell.Offset(0, 1).Value = "" Then
                    subfolderPath = FolderPath & "\" & Cell.Offset(0, 1).Value
                    If Not FolderExists(subfolderPath) Then MkDir subfolderPath
                End If
            End If
        Next Cell
    End Sub
    
    Function FolderExists(FolderPath As String) As Boolean
        On Error Resume Next
        FolderExists = (GetAttr(FolderPath) And vbDirectory) = vbDirectory
        On Error GoTo 0
    End Function
    

Langkah 3: Jalankan kodenya

  1. Setelah menempelkan kode ini, harap tekan F5 kunci untuk menjalankan kode ini. Di kotak prompt, pilih nilai sel yang ingin Anda buat foldernya. Lalu, klik OK.
  2. Di jendela yang muncul berikut, tentukan jalur tujuan untuk menampilkan folder yang dibuat. Lalu, klik OK tombol, lihat tangkapan layar:

Hasil:

Setelah menjalankan kode VBA, buka direktori tujuan untuk melihat hasilnya. Anda akan menemukan bahwa folder dan subfoldernya masing-masing, seperti yang ditentukan oleh nilai sel, telah berhasil dibuat seperti gambar berikut yang ditampilkan:

Tip:
  1. Kode ini hanya tersedia untuk membuat folder utama dan subfolder tingkat pertama saja.
  2. Jika Anda sering menggunakan kode ini, pertimbangkan untuk menyimpan buku kerja Anda Buku kerja Excel yang Diaktifkan Makro format. Tindakan ini mempertahankan kode di dalam buku kerja, memungkinkan Anda mengeksekusinya secara langsung di masa mendatang tanpa perlu memasukkan ulang atau mengimpor ulang kode tersebut.

Artikel Terkait:

  • Buat daftar semua folder dan subfolder di Excel
  • Pernahkah Anda mengalami masalah ini yang mencantumkan semua folder dan subfolder dari direktori tertentu ke dalam lembar kerja? Di Excel, tidak ada cara cepat dan praktis untuk mendapatkan nama semua folder di direktori tertentu sekaligus. Untuk menangani tugas tersebut, artikel ini dapat membantu Anda.
  • Menyalin atau memindahkan file dari satu folder ke folder lain berdasarkan daftar
  • Jika Anda memiliki daftar nama file di kolom di lembar kerja, dan file tersebut berada di folder di komputer Anda. Tapi, sekarang, Anda perlu memindahkan atau menyalin file-file ini yang namanya tercantum ke dalam lembar kerja dari folder aslinya ke folder lain seperti gambar berikut yang ditampilkan. Bagaimana Anda bisa menyelesaikan tugas ini secepat mungkin di Excel?
  • Ganti nama beberapa file dalam satu folder
  • Mungkin sebagian besar dari kita mengalami masalah ini sehingga kita perlu mengganti nama banyak file dalam satu folder, untuk mengganti nama nama file satu per satu akan membuat kita gila jika ada ratusan atau ribuan file di folder itu. Apakah ada fungsi yang baik bagi kita untuk menangani tugas ini?
Comments (63)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
níže CZ verze

EN:

A better way to do this in a few seconds is to use cmd (.bat file)

If you have a list of names in excel, add the word MKdir in front of the name (folder name) and if it contains a space put the name in quotes. Then just copy it to notepad, save as and add the .bat extension. Once you have this, substitute the .bat file in the folder where it wants to be created and you're done.

If you want the cmd not to close write at the end of the puase like below

Here is the 3 word code *5* :

start
________
MKdir "Pixie Pin"

pause
________
end


this creates a folder named Pixie Pin in the folder where the command was run

CZ:

Lepší způsob jak to udělat během par sec. je použít cmd (.bat soubor)

Pokud máte seznam jmen v excelu, doplňte pomocí vzorečku slovo MKdir před jmeno (název složky) a pokud obsahuje mezeru dejte název do uvozovek. Poté stačí jen zkopírovat do oznámkového bloku (NotePad), dát uložit jako a dopsat příponu .bat . Jakmile toto máte, supsťte .bat soubor ve složce kde chce aby se vytvořili a máte to.

Pokud chcete aby se cmd nezavřelo napište na konec puase jako je níže

Zde je ten 3 slovný kód *5* :

start
________
MKdir "Pixie Pin"

pause
________
konec


toto vytvoří složku s názvem Pixie Pin ve složce kde byl příkaz spuštěn
This comment was minimized by the moderator on the site
This worked really well, even for someone with zero experience with VBA :-)
Would it be possible to adapt the macro or extend the macro to also create hyperlinks to the folders in the selected cells?
So for instance, Cell A3 is selected and you run the macro and the folder is created. Would it be possible to make cell A3 a hyperlink to the folder by expanding on the macro instead of doing that manually?
This comment was minimized by the moderator on the site
Hello, Marloes
To create hyperlinks for the cell values, the following vba code may help you:

First, please select the cell values, and then run this code, and select a folder for outputting the folders.

Sub MakeFoldersAndAddHyperlinksWithFolderSelection()
    Dim Rng As Range
    Dim maxRows, maxCols, r, c As Integer
    Dim folderPath As String
    Dim baseFolderPath As String
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    
    With fd
        If .Show = -1 Then
            baseFolderPath = .SelectedItems(1) & "\"
        Else
            MsgBox "No folder selected. Operation Cancelled."
            Exit Sub
        End If
    End With
    
    Set Rng = Selection
    maxRows = Rng.Rows.Count
    maxCols = Rng.Columns.Count
    
    For c = 1 To maxCols
        For r = 1 To maxRows
            folderPath = baseFolderPath & Rng.Cells(r, c).Value
            If Len(Dir(folderPath, vbDirectory)) = 0 Then
                MkDir folderPath
                On Error Resume Next
                ActiveSheet.Hyperlinks.Add Anchor:=Rng.Cells(r, c), Address:=folderPath, TextToDisplay:=Rng.Cells(r, c).Value
                On Error GoTo 0
            End If
        Next r
    Next c
End Sub


Please have a try, thank you!
This comment was minimized by the moderator on the site
please, i need that same macro but instead of saving them as folders, i need it to save as Excels.
This comment was minimized by the moderator on the site
is it possible to introduce a condition where if that condition is met the module can create 2 folders (each using a different path)?
if the first list of folders is in the A column then the condition occurs in the U column. The conditional criteria is whether the cell is empty or not.
if the condition is not met the module only makes one folder based on the selection.
This comment was minimized by the moderator on the site
Hi, a_c, sorry I have not found a method can solve this job yet.
This comment was minimized by the moderator on the site
Thank you very much
This comment was minimized by the moderator on the site
Thanks a lot! Your VBA code is really super
This comment was minimized by the moderator on the site
Is it possible to import data from a word to excel on colors algorythme? So, I spell the cities with red and countries with blue in a word, and the to import only these to excel. I don’t know if I made myself clear. Thanks
This comment was minimized by the moderator on the site
Thank you, this has saved me literally days of work.
This comment was minimized by the moderator on the site
Hello,


For the following code it shows error in

MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))



It says Runtime error 76 path not found



Can someone please help me with this?

There are no unsupported characters in the file path.
Not sure what could be the problem

Thanks for the help!
This comment was minimized by the moderator on the site
thank you , time saved
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