Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3937|回复: 25

[已解决]菜鸟寻求帮忙改代码!

[复制链接]
发表于 2012-10-21 13:56 | 显示全部楼层 |阅读模式
菜鸟寻求帮忙改代码!谢谢!
最佳答案
2012-10-21 15:08
hhss123 发表于 2012-10-21 14:56
老大最终确定是10楼的代码吗!

11楼的吧。越是后面贴的,就越好点。

请教本代码要想在10中运行要怎么改.rar

189.3 KB, 下载次数: 10

发表于 2012-10-21 14:07 | 显示全部楼层
回复

使用道具 举报

发表于 2012-10-21 14:14 | 显示全部楼层
不过有点小问题,原来的不会清除,还有就是大小的问题。
回复

使用道具 举报

发表于 2012-10-21 14:18 | 显示全部楼层
pictures得改成图片了。
回复

使用道具 举报

发表于 2012-10-21 14:27 | 显示全部楼层
原有的那句改为
  1. If InStr(.Name, "图片") > 0 Then .Delete
复制代码
回复

使用道具 举报

发表于 2012-10-21 14:35 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2.     Dim oShp As Shape
  3.     Dim rng As Range, sPic As String
  4.     For Each oShp In Shapes
  5.         With oShp
  6.             If .Name Like "*Picture*" Or .Name Like "*图片*" Then .Delete
  7.         End With
  8.     Next
  9.     Application.ScreenUpdating = False
  10.     For Each rng In Range("a2:a" & [a65536].End(xlUp).Row)
  11.         sPic = ThisWorkbook.Path & "" & rng & ".jpg"
  12.         If Dir(sPic) <> "" Then
  13.             Pictures.Insert(sPic).Select
  14.             Selection.ShapeRange.LockAspectRatio = msoFalse
  15.             With rng
  16.                 Selection.Left = .Offset(0, 3).Left + 2
  17.                 Selection.Top = .Offset(0, 3).Top + 2
  18.                 Selection.Height = .Offset(0, 3).Height - 2
  19.                 Selection.Width = .Offset(0, 3).Width - 2
  20.             End With
  21.         End If
  22.     Next
  23.     Application.ScreenUpdating = True
  24.     [d1].Select
  25. End Sub
复制代码
回复

使用道具 举报

发表于 2012-10-21 14:36 | 显示全部楼层
奇怪,有时是图片,有时是PICTURE,直接都判断得了,然后去掉了锁定纵横比。
不然就得把行高根据图片的高度来设置了。
回复

使用道具 举报

发表于 2012-10-21 14:38 | 显示全部楼层
QQ截图20121021143824.jpg
03 里显示名字是图片
回复

使用道具 举报

发表于 2012-10-21 14:41 | 显示全部楼层
在10里新添加的图片是picture,原有的图片在未删之前是图片X QQ截图20121021144058.jpg 类似的名字
回复

使用道具 举报

发表于 2012-10-21 14:46 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2.     Dim oShp As Shape
  3.     Dim rng As Range, sPic As String
  4.     For Each oShp In Shapes
  5.         With oShp
  6.             If .Name Like "*Picture*" Or .Name Like "*图片*" Then .Delete
  7.         End With
  8.     Next
  9.     Application.ScreenUpdating = False
  10.     For Each rng In Range("a2:a" & [a65536].End(xlUp).Row)
  11.         sPic = ThisWorkbook.Path & "" & rng & ".jpg"
  12.         If Dir(sPic) <> "" Then
  13.             Pictures.Insert(sPic).Select
  14.             'Selection.ShapeRange.LockAspectRatio = msoFalse
  15.             With rng
  16.                 Selection.Left = .Offset(0, 3).Left + 2
  17.                 Selection.Top = .Offset(0, 3).Top + 2
  18.                 'Selection.Height = .Offset(0, 3).Height - 2
  19.                 Selection.Width = .Offset(0, 3).Width - 2
  20.                 .RowHeight = Selection.Height + 4
  21.             End With
  22.         End If
  23.     Next
  24.     Application.ScreenUpdating = True
  25.     [d1].Select
  26. End Sub
复制代码
10里图片由于默认是锁定纵横比的,所以一旦设置了宽度,图片的高度就会根据比例自动缩小。
再来设置图片的高度就无意义。
通过修改单元格的行高来适应图片的高度。这样图片的比例一致,相对于原图来说不会有失真。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 16:19 , Processed in 0.356647 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表