|
楼主 |
发表于 2022-11-24 21:18
|
显示全部楼层
我把代码分享出来,供大家参考
1、关键:菜单--选项--高级--勾选“不压缩文件中的图片”
2、为避免文件容量过大,可以采用iSee软件对图片进行压缩预处理,插入过程中弹出对话框,也可以勾选对插入的图片进行压缩,但没有iSee软件高效
Sub 插入图片()
Dim sh As Shape, C As Range
Application.Dialogs(xlDialogInsertPicture).Show
If TypeName(Selection) = "Picture" Then
CommandBars("Picture").Controls(10).Execute
'Set C = Application.InputBox("请选择单元格", Type:=8)
'C.ColumnWidth = 5 '单元格列宽
'C.RowHeight = 20 '单元格行高
Set C = ActiveCell
With Selection
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).LockAspectRatio = msoFalse
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Width = C.Width
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Height = C.Height
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Left = C.Left
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Top = C.Top
.OnAction = "test"
.Name = ActiveCell.Address(0, 0)
End With
End If
End Sub
Sub test()
On Error Resume Next
For Each a In ActiveSheet.Shapes
nm = Application.Caller
If nm <> "I1" Then
If a.Name = nm Then
If a.AlternativeText = Empty Then
a.AlternativeText = a.Height & Chr(28) & a.Width
a.Height = a.Height * 27
a.Width = a.Height * 1
a.ZOrder msoBringToFront
Else
a.Height = Split(a.AlternativeText, Chr(28))(0)
a.Width = Split(a.AlternativeText, Chr(28))(1)
a.AlternativeText = Empty
End If
Err.Clear
End If
End If
Next
End Sub
Sub 删除图片()
Dim p As Shape
For Each p In ActiveSheet.Shapes
If p.Type = 13 Then p.Delete
Next
End Sub
Sub 隐藏图片()
For i = 1 To ActiveSheet.Shapes.Count
ActiveSheet.Shapes(i).Visible = msoFalse
Next i
End Sub
Sub 显示图片()
For i = 1 To ActiveSheet.Shapes.Count
ActiveSheet.Shapes(i).Visible = msoTrue
Next i
End Sub
|
|