Vpiši se  \/ 
x
or
x
Registracija  \/ 
x

or

Kako našteti vse mape in podmape v Excelu?

Ste že kdaj trpeli zaradi te težave, ki vsebuje vse mape in podmape iz določenega imenika na delovni list? V Excelu ni na hiter in priročen način, da naenkrat dobite ime vseh map v določenem imeniku. Ta članek vam bo morda v pomoč pri reševanju naloge.

Seznam vseh map in podmap s kodo VBA

Kartica Office Omogočite urejanje in brskanje z zavihki v storitvi Office ter olajšajte svoje delo ...
Kutools za Excel rešuje večino vaših težav in poveča produktivnost za 80%
  • Ponovno uporabi vse: Med priljubljene dodajte najbolj uporabljene ali zapletene formule, grafikone in kar koli drugega ter jih v prihodnosti hitro ponovno uporabite.
  • Več kot 20 besedilnih funkcij: Izvleček številke iz besedilnega niza; Izvleči ali odstrani del besedil; Pretvorite številke in valute v angleške besede.
  • Združi orodja: Več delovnih zvezkov in listov v eno; Združi več celic / vrstic / stolpcev brez izgube podatkov; Združi podvojene vrstice in vsoto.
  • Razdeljena orodja: Razdeli podatke na več listov na podlagi vrednosti; En delovni zvezek v več datotek Excel, PDF ali CSV; En stolpec na več stolpcev.
  • Prilepi preskoči Skrite / filtrirane vrstice; Štetje in vsota glede na Barva ozadja; V večjem obsegu pošiljajte osebna e-poštna sporočila več prejemnikom.
  • Super filter: Ustvarite napredne filtrirne sheme in uporabite za vse liste; Razvrščanje po tednih, dnevih, pogostosti in še več; filter s krepkim tiskom, formule, komentar ...
  • Več kot 300 zmogljivih funkcij; Deluje s sistemoma Office 2007-2019 in 365; Podpira vse jezike; Preprosta namestitev v vašem podjetju ali organizaciji.

puščica modri desni mehurček Seznam vseh map in podmap s kodo VBA


Če želite iz določenega imenika dobiti vsa imena map, vam bo morda v pomoč naslednja koda VBA, naredite naslednje:

1. Držite tipko ALT + F11 in odpre tipko Okno Microsoft Visual Basic for Applications.

2. Kliknite Vstavi > Moduliin prilepite naslednjo kodo v Okno modula.

Koda VBA: navedite imena vseh map in podmap

Sub FolderNames()
'Update 20141027
Application.ScreenUpdating = False
Dim xPath As String
Dim xWs As Worksheet
Dim fso As Object, j As Long, folder1 As Object
With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Choose the folder"
    .Show
End With
On Error Resume Next
xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
xWs.Cells(1, 1).Value = xPath
xWs.Cells(2, 1).Resize(1, 5).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.getFolder(xPath)
getSubFolder folder1
xWs.Cells(2, 1).Resize(1, 5).Interior.Color = 65535
xWs.Cells(2, 1).Resize(1, 5).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Sub getSubFolder(ByRef prntfld As Object)
Dim SubFolder As Object
Dim subfld As Object
Dim xRow As Long
For Each SubFolder In prntfld.SubFolders
    xRow = Range("A1").End(xlDown).Row + 1
    Cells(xRow, 1).Resize(1, 5).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified)
Next SubFolder
For Each subfld In prntfld.SubFolders
    getSubFolder subfld
Next subfld
End Sub

3. Nato pritisnite F5 tipko za zagon te kode in a Izberite mapo se bo odprlo okno, nato morate izbrati imenik, v katerega želite navesti imena map in podmap, glejte posnetek zaslona:

doc-list-folder-names-1

4. Kliknite OK, pot do mape in podmap, imenik, ime, datum ustvarjanja in datum zadnje spremembe pa boste dobili v novem delovnem zvezku, glejte posnetek zaslona:

doc-list-folder-names-1


Povezani članek:

Kako našteti datoteke v imeniku na delovnem listu v Excelu?


Najboljša orodja za pisarniško produktivnost

Kutools za Excel rešuje večino vaših težav in poveča produktivnost za 80%

  • Ponovna uporaba: Hitro vstavite zapletene formule, grafikoni in vse, kar ste že uporabljali; Šifriraj celice z geslom; Ustvari poštni seznam in pošiljanje e-pošte ...
  • Vrstica Super Formula (enostavno urejanje več vrstic besedila in formule); Bralna postavitev (enostavno branje in urejanje velikega števila celic); Prilepite v filtrirani obseg...
  • Združi celice / vrstice / stolpce brez izgube podatkov; Vsebina razdeljenih celic; Združi podvojene vrstice / stolpce... prepreči podvojene celice; Primerjaj obsege...
  • Izberite Duplicate ali Unique Vrstice; Izberite prazne vrstice (vse celice so prazne); Super Find in Fuzzy Find v mnogih delovnih zvezkih; Naključna izbira ...
  • Natančna kopija Več celic brez spreminjanja sklica formule; Samodejno ustvarjanje referenc na več listov; Vstavi oznake, Potrditvena polja in še več ...
  • Izvleček besedila, Dodaj besedilo, Odstrani po položaju, Odstrani presledek; Ustvari in natisni vmesne seštevke strani Pretvarjanje med vsebino celic in komentarji...
  • Super filter (shranite in uporabite sheme filtrov za druge liste); Napredno razvrščanje glede na mesec / teden / dan, pogostost in drugo; Poseben filter s krepko, ležeče ...
  • Združite delovne zvezke in delovne liste; Spoji tabele na podlagi ključnih stolpcev; Razdelite podatke na več listov; Paketna pretvorba xls, xlsx in PDF...
  • Več kot 300 zmogljivih funkcij. Podpira Office / Excel 2007-2019 in 365. Podpira vse jezike. Preprosta namestitev v vašem podjetju ali organizaciji. Vse funkcije 30-dnevnega brezplačnega preskusa. 60-dnevno jamstvo za vračilo denarja.
zavihek kte 201905

Kartica Office prinaša vmesnik z zavihki v Office in poenostavi vaše delo

  • Omogočite urejanje in branje z zavihki v Wordu, Excelu, PowerPointu, Publisher, Access, Visio in Project.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Poveča vašo produktivnost za 50% in vsak dan zmanjša na stotine klikov z miško!
dno pisarniške mize
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Ezel K. · 2 months ago
    Thank you very much for this usefull code. is that possible save result in same workbook not to new one ?

  • To post as a guest, your comment is unpublished.
    D Rodrigues · 8 months ago
    This worked and how... Thank you so much. Just one addition-- at Step 3, I had to click on Step Into and then only did the F5 key work for choosing the folder.
  • To post as a guest, your comment is unpublished.
    José · 11 months ago
    Thank you so much!, very useful.
  • To post as a guest, your comment is unpublished.
    David · 1 years ago
    Just what I needed, and perfectly clear instructions on how to make it work. Thanks a lot
  • To post as a guest, your comment is unpublished.
    jose · 1 years ago
    Great Tool! After long research found this accurate toy :)
  • To post as a guest, your comment is unpublished.
    lloyd · 2 years ago
    Hello. Can you please please help me on a code which I am struggling to find.

    Below are the requirements for the code.



    1. The VBA should go through all the folders and sub-folders
    and check each and every type of file. The user should only give the path for
    the top folder. The code should then check all the folders and sub folders
    within the top folder.



    2. After checking the files, the code should zip all files
    which have not been accessed for more than 3 months. The accessed period is
    something which I should be able to change in future if required. It should
    allow me to change it to 1 month or 5 months if required.



    3. After zipping the files, the code should delete the
    original files which were zipped.



    4. The zipped file should be saved in the same path as the
    original file.
  • To post as a guest, your comment is unpublished.
    tom vincent · 3 years ago
    I modified it to add size:



    Sub FolderNames()
    'Update 20141027
    Application.ScreenUpdating = False
    Dim xPath As String
    Dim xWs As Worksheet
    Dim fso As Object, j As Long, folder1 As Object
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Choose the folder"
    .Show
    End With
    On Error Resume Next
    xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
    Application.Workbooks.Add
    Set xWs = Application.ActiveSheet
    xWs.Cells(1, 1).Value = xPath
    xWs.Cells(2, 1).Resize(1, 6).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified","Size")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder1 = fso.getFolder(xPath)
    getSubFolder folder1
    xWs.Cells(2, 1).Resize(1, 6).Interior.Color = 65535
    xWs.Cells(2, 1).Resize(1, 6).EntireColumn.AutoFit
    Application.ScreenUpdating = True
    End Sub
    Sub getSubFolder(ByRef prntfld As Object)
    Dim SubFolder As Object
    Dim subfld As Object
    Dim xRow As Long
    For Each SubFolder In prntfld.SubFolders
    xRow = Range("A1").End(xlDown).Row + 1
    Cells(xRow, 1).Resize(1, 6).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified, SubFolder.Size)
    Next SubFolder
    For Each subfld In prntfld.SubFolders
    getSubFolder subfld
    Next subfld
    End Sub
    • To post as a guest, your comment is unpublished.
      AL · 3 years ago
      When you include the SubFolder.Size function the script no longer list all the subfolders, only the first level.
      How can I include the size and get all subfolders listed?
  • To post as a guest, your comment is unpublished.
    jimbosmiles · 3 years ago
    I am with the others - it works up to a point.

    For me, that point is it creates the new s/s, details the folder I have shown (in Cells A1), the a yellow highlighted bar in row 2 with the headings followed by nothing else!

    The folder I am looking at is empty except for sub folders (i.e. no data files exist) and the sub folders do not appera at all.

    Can anyone help me list the sub folders and their files?
  • To post as a guest, your comment is unpublished.
    Paul J · 3 years ago
    When I run this code it works but it only shows the first folder in side the folder that I choose. For example,

    When I run the code I choose "C:\Users\Johnson\Music" (Note: I have 70 Folders inside my Music Folder)

    When the code runs it only shows the first folder and then list all the folders inside that folder.

    I would like it to list all the folders inside the Music folder.
  • To post as a guest, your comment is unpublished.
    Caralyn · 3 years ago
    Hello,
    I just followed your directions but I'm getting errors when I hit F5 to run. The error below highlights "Dim xWs As Worksheet". Is there an updated code I can use?
    Compile error:
    User-defined type not defined
    • To post as a guest, your comment is unpublished.
      Robert Poole · 3 years ago
      [quote name="Caralyn"]Hello,
      I just followed your directions but I'm getting errors when I hit F5 to run. The error below highlights "Dim xWs As Worksheet". Is there an updated code I can use?
      Compile error:
      User-defined type not defined[/quote]

      Are you using the Kutools add-on or MS Excel VBA editor? Since I am not using the add-on, I am unable to duplicate your error. Using MS VBA Editor works without any errors.
  • To post as a guest, your comment is unpublished.
    Robert Poole · 3 years ago
    This code truly saved the day. Thank you for sharing it.
  • To post as a guest, your comment is unpublished.
    MMB · 4 years ago
    What if i need to create the link also for the folder what should i modify in the coding and cant we create button and link the same coding to it, so it will be useful for the users who dont know how to run macros
    • To post as a guest, your comment is unpublished.
      Robert Poole · 3 years ago
      I did exactly what your requesting. I placed my companies logo on the whorksheet, then I right-clicked on it and assigned a macro (which is the above code.)
      You can also insert how-to used user instructions.
  • To post as a guest, your comment is unpublished.
    Dahamou ayman · 4 years ago
    Thanks a lot.I was using cmd prompt to have a txt with my folders then copy it on excel but now u make things easy for me :)