如何在 Excel 中一次性插入多张图片并调整它们的大小?

使用以下 VBA 代码,你可以逐个单元格地将多张图片插入到 Excel 文件中。

1. 选择你要插入图片的目标区域的第一个单元格。

2. 按住 ALT + F11 键,打开 Microsoft Visual Basic for Applications 窗口。

3. 点击 插入 > 模块,并将以下宏粘贴到 模块窗口中。

Sub InsertPictures()

'Update 20140513

Dim PicList() As Variant

Dim PicFormat As String

Dim Rng As Range

Dim sShape As Shape

On Error Resume Next

PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)

xColIndex = Application.ActiveCell.Column

If IsArray(PicList) Then

xRowIndex = Application.ActiveCell.Row

For lLoop = LBound(PicList) To UBound(PicList)

Set Rng = Cells(xRowIndex, xColIndex)

Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)

xRowIndex = xRowIndex + 1

Next

End If

End Sub

4. 然后按 F5 键运行此代码。

5. 在“打开”对话框中,请打开包含你想插入的图片的文件夹,选择你要插入的多张图片,然后点击“打开”按钮。所有选定的图片都将根据单元格大小导入到你的选择中。见截图:


幽魂魅影套装介绍套装介绍 以及黄白字的区分
揭秘坏男孩软件:功能特点及用户使用心得分享