Excel 如何检查单元格内图片的名称?
我想检查单元格中图片的名称,然后根据图片的名称在下一列中输入一个值 我的程序只检查活动表中是否存在图片的名称Excel 如何检查单元格内图片的名称?,excel,vba,Excel,Vba,我想检查单元格中图片的名称,然后根据图片的名称在下一列中输入一个值 我的程序只检查活动表中是否存在图片的名称 Sub CheckImageName() Dim iRowCountShapes As Integer Dim sFindShape As String iRowCountShapes = 2 While Sheets("Data").Cells(iRowCountShapes, 1) <> "" If Sheets("D
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
子检查图像名称()
Dim iRowCountShapes为整数
将形状设置为字符串
iRowCountShapes=2
而图纸(“数据”)。单元格(iRowCountShapes,1)”
如果图纸(“数据”)形状(“岩石”).Name=“岩石”,则
表格(“数据”)。单元格(iRowCountShapes,3)=“岩石”
其他表格(“数据”).Shapes(“滚动”).Name=“滚动”然后
表格(“数据”)。单元格(iRowCountShapes,3)=“滚动”
其他的
表格(“数据”)。单元格(iRowCountShapes,3)=“两者都不”
如果结束
iRowCountShapes=iRowCountShapes+1
温德
端接头
图片不在单元格中,而是在工作表上方的绘图层中。只需循环浏览图片,并根据图片左上角下的单元格将名称放在相关列中,就更容易了:
Sub CheckImageName()
Dim pic As Excel.Picture
For Each pic In ActiveSheet.Pictures
pic.TopLeftCell.Offset(, 2).Value2 = pic.Name
Next pic
End Sub
图片不在单元格中,而是在工作表上方的绘图层中。只需循环浏览图片,并根据图片左上角下的单元格将名称放在相关列中,就更容易了:
Sub CheckImageName()
Dim pic As Excel.Picture
For Each pic In ActiveSheet.Pictures
pic.TopLeftCell.Offset(, 2).Value2 = pic.Name
Next pic
End Sub
Excel中的图像可以观察为形状。如果它们在insert中正确命名(使用实际文件名),那么您可以像这样迭代它们
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生成的图像名称:
- 图1
- 图2
- 图3
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生成的图像名称:
- 图1
- 图2
- 图3
录制宏,将对象复制并粘贴到任意位置,停止录制。删除粘贴的对象。查看刚刚创建的宏的代码,在vba中可以看到对象的名称。删除宏。首先,我必须澄清,在我的世界里,我会尽一切努力使事情正常运行,因此,下面是我获取对象名称的低级方法
录制宏,将对象复制并粘贴到任意位置,停止录制。删除粘贴的对象。查看刚刚创建的宏的代码,在vba中可以看到对象的名称。删除宏。谢谢@StefanMichev。问题解决了。谢谢@StefanMichev。问题解决了。