EXCEL VBA 显示图片
2,如何在控件中显示呢?比如我添加一个控件A(是什么控件呢)另外添加一个click(点击这个click,在控件A中显示图片)
感谢各位了!!!另外有学习代码的网站吗,思路我看了一般都知道,因为学过编程,但是EXCEL的对象属性,语言方式有点不同~~
Private Sub Image2_Click()
If Image2.Picture = LoadPicture("") Then
Image2.Picture = LoadPicture("F:\小曾文件夹\未命名.jpg")
Else
Image2.Picture = LoadPicture("")
End If
这样写有错吗 帮我改改 最好有注释~~ 展开
有两种情况:
如果图片显示到整个单元格的话,可以直接在Y2单元格写没有这个图片。
然后如果有图片会把字覆盖,看不见,没有图片则可以看见字,不需要代码写这个。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Count = 1 And Target.Column = 4 Then
On Error Resume Next
Shapes("@@@@@").Delete
If Dir(ThisWorkbook.Path & "\" & Target.Value & ".jpg") <> "" Then
[Y2] = ""
ActiveSheet.Shapes.AddPicture(ThisWorkbook.Path & "\" & Target.Value & ".jpg", 1, 1, [Y2].Left + 5, [Y2].Top + 5, [Y2].Width - 10, [Y2].Height - 10).Name = "@@@@@"
Else
[Y2] = "没有这个图片"
End If
End If
End Sub
Sub Macro5()
Dim xlsheet As Worksheet
Set xlsheet = ActiveSheet
With xlsheet.Pictures.Insert("F:/A/a.jpg")
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Line.Visible = msoTrue
.ShapeRange.Left = xlsheet.Range("A1").Left
.ShapeRange.Top = xlsheet.Range("A1").Top
.Visible = True
End With
End Sub
2)插入Image1控件
Image1.Picture = LoadPicture("F:/A/a.jpg")
if语句有误
Private Sub Image2_Click()
'Image2.Picture返回的是对象,LoadPicture("")返回的结果是Nothing,不是True或False
If Image2.Picture Is Nothing Then
Image2.Picture = LoadPicture("D:\1.jpg")
Else
Image2.Picture = LoadPicture("")
End If
End Sub