跳到主要内容

如何在Excel单元格中快速列出文件夹的图片名称/文件名?

在本教程中,我将提供一些技巧,以快速显示Excel表格中特定文件夹的所有图片名称或文件名,如屏幕快照所示。

快速导航

使用VBA列出Excel中文件夹的图片名称
使用“文件名列表”列出Excel中文件夹的图片名称或特定格式的文件名
下载样本文件

doc列表图片名称1

使用VBA列出Excel中文件夹的图片名称

在Excel中,没有内置的功能可以自动列出您在工作表的单元格中选择的文件夹的所有图片名称,但是这里有一个VBA代码可以帮助您快速解决此问题。

1.在Excel中,然后按 + 打开钥匙 Microsoft Visual Basic应用程序 窗口。

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 Kutools for Excel,这可以

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

>>以您为Excel指定的一种或几种文件格式列出文件名;

>>将文件名(包括子文件夹,隐藏文件和文件夹)列出到Excel。

跟老鼠手和颈椎病说再见

Kutools for Excel 的 300 个高级工具解决 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’ 创建工作表名称列表 实用程序,它将创建一个新的工作表以列出所有可链接的工作表名称。
创建工作表名称列表

Kutools for Excel:+有用的便捷工具,只需单击几下即可简化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