如何检查单元内图片的名称? [英] How to Check the Name of Picture Inside the Cell?

查看:81
本文介绍了如何检查单元内图片的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查单元格中的图片名称,然后根据图片名称在下一列中输入一个值.

I want to check the name of the picture in a cell, then put a value on the next column based on the name of the picture.

我的程序仅检查图片名称是否存在于活动表中.

My program only checks if the name of the picture exists in the activesheet.

Sub CheckImageName()
    Dim iRowCountShapes As Integer
    Dim sFindShape As String

    iRowCountShapes = 2

    While Sheets("Data").Cells(iRowCountShapes, 1) <> ""

        If Sheets("Data").Shapes("Rock").Name = "Rock" Then

            Sheets("Data").Cells(iRowCountShapes, 3) = "Rock"

        ElseIf Sheets("Data").Shapes("Roll").Name = "Roll" Then

            Sheets("Data").Cells(iRowCountShapes, 3) = "Roll"

        Else

            Sheets("Data").Cells(iRowCountShapes, 3) = "Neither"

        End If

        iRowCountShapes = iRowCountShapes + 1

    Wend

End Sub

推荐答案

可以将Excel中的图像视为形状.如果在插入时正确命名了它们(使用真实文件名),则可以像这样

Images in Excel can be obsereved as shapes. If they are named correctly(with real filename) on insert then you can iterate through them like this

Private Sub CommandButton1_Click()
Dim doc As Worksheet
Dim spe As Shape

Set doc = Worksheets(1)

For i = 1 To doc.Shapes.Count - 1
    Set spe = doc.Shapes(i)

    'for named images
    Debug.Print doc.Shapes(i).Name

    spe.Select

    'for linked images
    Debug.Print GetSourceInfo(spe)
Next

End Sub

Function GetSourceInfo(oShp As Shape) As String
    On Error GoTo Error_GetSourceInfo
    GetSourceInfo = oShp.LinkFormat.SourceFullName
    Exit Function
Error_GetSourceInfo:
   GetSourceInfo = ""
End Function

在我的案例中,这显示了excel生成的图像名称:

Which in my case shows the excel generated imagenames:

  • 图片1
  • 图片2
  • 图片3

这篇关于如何检查单元内图片的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆