跳到主要內容

如何在Excel單元格中快速列出文件夾的圖片名稱/文件名?

在本教程中,我將提供一些技巧,以快速顯示Excel表格中特定文件夾的所有圖片名稱或文件名,如圖所示。

快速導航

使用VBA列出Excel中文件夾的圖片名稱
使用“文件名列表”列出Excel中文件夾的圖片名稱或特定格式的文件名
下載樣本文件

doc列表圖片名稱1

使用VBA列出Excel中文件夾的圖片名稱

在Excel中,沒有內置的功能可以自動列出您在工作表的單元格中選擇的文件夾的所有圖片名稱,但是這裡我有一個VBA代碼,可以幫助您快速解決此工作。

1.在Excel中,然後按 + 打開鑰匙 Microsoft Visual Basic for Applications 窗口。

2.在彈出的窗口中,單擊 插入 > 模塊 創建一個新的模塊腳本。

3.複製以下代碼並將其粘貼到新的“模塊腳本”窗口中。

Sub PictureNametoExcel()
'UpdatebyExtendoffice 
    Dim I As Long
    Dim xRg As Range
    Dim xAddress As String
    Dim xFileName As String
    Dim xFileDlg As FileDialog
    Dim xFileDlgItem As Variant
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Select a cell to place name list:", "Kutools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xRg = xRg(1)
    xRg.Value = "Picture Name"
    With xRg.Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 10
    End With
    xRg.EntireColumn.AutoFit
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    I = 1
    If xFileDlg.Show = -1 Then
        xFileDlgItem = xFileDlg.SelectedItems.Item(1)
        xFileName = Dir(xFileDlgItem & "\")
        Do While xFileName <> ""
            If InStr(1, xFileName, ".jpg") + InStr(1, xFileName, ".png") + InStr(1, xFileName, ".img") + InStr(1, xFileName, ".ioc") + InStr(1, xFileName, ".bmp") > 0 Then
                xRg.Offset(I).Value = xFileDlgItem & "\" & xFileName
                I = I + 1
            End If
            xFileName = Dir
        Loop
    End If
    Application.ScreenUpdating = True
End Sub

4。 按 F5 鍵,然後會彈出一個對話框供您選擇用於放置圖片名稱的單元格。
doc列表圖片名稱1

5。 點擊 OK 繼續選擇要在“瀏覽”對話框中列出圖片名稱的文件夾。
doc列表圖片名稱3

6。 點擊 OK,現在已在Excel中列出了所選文件夾中的所有圖片名稱。
doc列表圖片名稱13

注意: 在VBA代碼中,您可以在代碼字符串中使用jpg / png /… 如果InStr(1,xFileName,“ .jpg”)+ InStr(1,xFileName,“ .png”)+ InStr(1,xFileName,“ .img”)+ InStr(1,xFileName,“ .ioc”)+ InStr (1,xFileName,“。bmp”) > 0然後 到所需的文件擴展名,例如,如果要以doc格式列出文件的文件名,只需將代碼字符串更改為 如果InStr(1,xFileName,“ .doc”)> 0然後。

如果您在日常工作中通常需要在Excel單元格中列出文件夾的一種或所有格式的文件名,則代碼很複雜且不易處理,但是通過以下方式,您可以快速解決此問題。


其他

您想加薪並有很多時間陪伴家人嗎?

Office選項卡可將Microsoft Office立即工作的效率提高50%

令人難以置信的是,處理兩個或多個文檔比處理一個或多個文檔更容易,更快捷。

與知名瀏覽器相比,Office Tab中的選項卡式工具功能更強大,更高效。

每天為您減少數百次鼠標單擊和鍵盤輸入,現在告別鼠標手。

如果您通常處理多個文檔,Office Tab將為您節省大量時間。

30-天免費試用,無需信用卡。

了解更多 現在免費下載


使用“文件名列表”列出Excel中文件夾的圖片名稱或特定格式的文件名

這是一個實用程序– 文件名列表 in Excel的Kutools, 哪個行

>>在新工作表中列出文件夾的所有文件格式的所有文件名;

>>以您為Excel指定的一種或幾種文件格式列出文件名;

>>將文件名(包括子文件夾和隱藏文件及文件夾)列出到Excel。

告別鼠標手和頸椎病

300個高級工具 Kutools for Excel 解決 企業排放佔全球 80% 數秒內完成 Excel 任務,讓您擺脫數千次鼠標點擊。

輕鬆應對1500個工作場景,無需浪費時間尋找解決方案,有更多時間享受生活。

每天為 80+ 高效能人士提高 110000% 的生產力,當然也包括你。

不再被痛苦的公式和VBA折磨,給你的大腦一個休息和快樂的工作心情。

30 天免費試用全功能,30 天無理由退款。

更好的身體創造更好的生活。

免費安裝Kutools for Excel後,請執行以下操作:

1.啟用要列出文件名的工作簿,然後單擊 Kutools 加 > 進出口 > 文件名列表.
doc列表圖片名稱4

2。 在裡面 文件名列表 對話框,首先,單擊  doc列表圖片名稱5 選擇要列出其文件名的文件夾,然後可以選中以下複選框 在子目錄中包含文件 包括隱藏的文件和文件夾 如你所需。
doc列表圖片名稱6

3.然後選擇要在其中列出名稱的文件格式 檔案類型 部分。

格紋 所有文件 選項,它將列出所選文件夾中所有文件格式的所有文件名
doc列表圖片名稱7
格紋 共同 選項,然後從下拉列表中選擇要列出文件名的特定文件格式,然後它將列出您在下拉列表中選擇的文件格式的所有文件名
doc列表圖片名稱8
格紋 指定 選項,然後在文本框中鍵入要在列表中列出文件名的文件擴展名(使用逗號分隔),然後它將僅在Excel中列出帶有輸入文件擴展名的文件名
doc列表圖片名稱9

4.根據需要從下拉列表中選擇尺寸單位 文件大小單位 部分,如果您要創建文件名的鏈接,請檢查 創建超鏈接 選項。

doc列表圖片名稱10 doc列表圖片名稱11

5。 點擊 Ok,將創建一個新工作表來列出文件名和一些文件信息。
doc列表圖片名稱12

小提示: 如果要在Excel中列出所有工作表名稱,可以將Kutools for Excel' 創建工作表名稱列表 實用程序,它將創建一個新的工作表以列出所有可鏈接的工作表名稱。
創建工作表名稱列表

Excel的Kutools:+有用的便捷工具,只需單擊幾下即可簡化Excel中的複雜任務。


下載樣本文件

樣品


如何使您從人群中脫穎而出,輕鬆工作並悠閒地享受生活?

Kutools for Excel 平均每天會提升您 80% 的效率,讓您有更多的時間陪伴家人,享受生活的樂趣。

300個高級工具解決 企業排放佔全球 80% Excel 問題,您不再苦苦尋找解決方案,更輕鬆地完成工作。

輕鬆處理1500個Excel場景,每天為您節省至少1小時。

在5分鐘內成為Excel專家,獲得人們的認可和晉昇機會。

一鍵式實用程序處理批處理,使您避免數千次鼠標單擊,與鼠標手說再見。

擺脫死記硬背的公式和復雜的VBA,讓您的大腦休息一下。

110000多名高效率官員和300多家世界知名公司的選擇。

僅花費$ 39,但比$ 4000的其他人培訓更有價值

30 天免費試用,無任何限制,30 天全額退款,無任何理由。


推薦的生產力工具

Office選項卡-Microsoft Office 2019-2003和Office 365中的選項卡式瀏覽,編輯,文檔管理


辦公室標籤

一個用於加速Excel 2019-2007的專業加載項,可將小時任務縮減為幾秒鐘

此外接程序包括數十個專業組,具有300多個選項,可以自動執行Excel中的大多數日常任務,並至少使生產率提高50%。 例如一組一鍵式opton和批量轉換。
現在,您可以使用Kutools for Excel加快自己的速度!


Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hey! This is super quick and thanks
This comment was minimized by the moderator on the site
Thanks so much for this!
This comment was minimized by the moderator on the site
In Libreoffice Calc I use the function of importing a list of files into the rows / columns of a Calc table, via Macro and based on certain criteria - I have created a button on the toolbar for this particular macro, and after pressing it, I select a folder, and the list of images is immediately inserted into a new document. How to make it as easy as possible in Excel? I have a lot of folders that contain 1 or more images and I need to:
> If the folder contains 1 image, I need it to be on a new line in Excel.
> If the folder contains more images, the first being on a new line and the second either:
- next to the first in the same row (in one column), separated by the character | (example: photo 1.jpeg | photo 2.jpeg)
- or to have their names in the columns (even without the | character) (the first option would be better, but the second is enough as well)

These are the product images whose names I need for import into Woocommerce - via a csv file.
This comment was minimized by the moderator on the site
Amazing! Thank you for sharing!
This comment was minimized by the moderator on the site
Hi,
As per the above code I am getting the the images name in an incrementing order, however the path where the images are being placed are in numeric incrementation.

Kindly suggest how I can keep the same formatting.
This comment was minimized by the moderator on the site
How to export an image with specific file name in excel.
This comment was minimized by the moderator on the site
I WAS HAVING THE SAME PROBLEM TANNER, IN THE SCRIPT WHERE IT HAS THE DIFFERENT FILE EXTENSIONS ITS GOING TO GRAB,YOU HAVE TO CAPITALIZE THE FILE EXTENSION ITS LOOKING FOR, FOR EXAMPLE, YOU SAID YOUR FILES ARE ".png", WELL IF YOU CAPITALIZE IT I.E ".PNG" IT MAY WORK.
This comment was minimized by the moderator on the site
Now it works for me. Thanks!!!
This comment was minimized by the moderator on the site
Is it possible that there is something wrong with the code? The file explorer is showing my folder full of images (.png) as empty.
This comment was minimized by the moderator on the site
Is it possible something is wrong with the code? Because it shows folders full of images (.png) as empty when it pulls up the box to select the photos.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations