在Excel文件

时间:2016-01-06 20:08:19

标签: excel excel-vba vba

我从客户端收到一个大的.xlsx文件,其中有数百张图片直接插入文件中。

我正在尝试以编程方式或使用宏输出新列中图像的名称(甚至更好的文件名)。

你能指出我正确的方向吗?

提前感谢您的时间。

1 个答案:

答案 0 :(得分:0)

希望这对你有所帮助。

Sub takePictureNames()
    Dim i As Integer 'use as index
    Dim Pic 'to store pictures in worhsheet

    i = 0 'init the index

    For Each Pic In ActiveSheet.Shapes
        i = i + 1 'add 1 every time
        Cells(i, 1).Value = Pic.Name
        'Cells({a}, {b}).value = {c}
        'a = the row. Using the index to take a row at the time
        'b = define the columns you want, with a variable or hardcoded as I did
        'c = inside the Pic variable, you store a picture, one at the time, and then take the name of the pic
        'Remember: The name of the picture is the name that excel gives to the picture once is inserted, not an
        'actual file name. But if you want to use it to run a macro, will be usefull to that that name (the excel name)
    Next Pic
End Sub

评论中的解释。