Excel精英培训网

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

[已解决]代码疑难,高手看哈

[复制链接]
发表于 2015-5-22 18:42 | 显示全部楼层 |阅读模式
本帖最后由 白云无尽9987 于 2015-5-22 18:52 编辑

n.rar (9.04 KB, 下载次数: 21)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-5-22 23:57 | 显示全部楼层
  1. Sub main()
  2.     Dim Ads As String, Desktop As String
  3.     If TypeName(Selection) <> "Range" Then MsgBox "必须选择单元格!", , "提示": Exit Sub
  4.     If Selection.Areas.Count > 1 Then MsgBox "只能选择一个区域!", , "提示": Exit Sub
  5.     Ads = VBA.Replace(VBA.Replace(Selection.Address, ":", "-"), "$", "")
  6.     Desktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
  7.     Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
  8.     ActiveSheet.Pictures.Paste.Select
  9.     With Selection
  10.         .Copy
  11.         With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, Selection.Height).Chart
  12.             .Paste
  13.             .Export Desktop & "" & Ads & ".jpg"
  14.             .Parent.Delete
  15.         End With
  16.         .Delete
  17.     End With
  18. '    Shell "explorer.exe " & Desktop, vbMaximizedFocus  '打开文件夹
  19. End Sub
复制代码
不知道你的区域会不会改,所以我是根据选中的单元格来确定导出图片的范围的。如果你要改成固定的,你把selection.address 改成你想要的单元格就可以了。

n.zip

18.29 KB, 下载次数: 7

评分

参与人数 1 +1 收起 理由
白云无尽9987 + 1 很给力!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2015-5-23 12:07 | 显示全部楼层
xdragon 发表于 2015-5-22 23:57
不知道你的区域会不会改,所以我是根据选中的单元格来确定导出图片的范围的。如果你要改成固定的,你把sele ...

高手高手高高手!!!啊,太感谢了!!!
回复

使用道具 举报

 楼主| 发表于 2015-5-23 12:17 | 显示全部楼层
xdragon 发表于 2015-5-22 23:57
不知道你的区域会不会改,所以我是根据选中的单元格来确定导出图片的范围的。如果你要改成固定的,你把sele ...

改成固定区域A2:B5,怎么改?——不要笑喷啊,我什么也不懂的,劳烦!
回复

使用道具 举报

发表于 2015-5-23 12:33 | 显示全部楼层
  1. Sub main()
  2.     Dim Rng As Range, Desktop As String
  3.     If TypeName(Selection) <> "Range" Then MsgBox "必须选择单元格!", , "提示": Exit Sub
  4.     If Selection.Areas.Count > 1 Then MsgBox "只能选择一个区域!", , "提示": Exit Sub
  5.     Set Rng = Range("A2:B5") '如果需要更改区域只需要更改这里的就可以了。
  6.     Desktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
  7.     Rng.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
  8.     ActiveSheet.Pictures.Paste.Select
  9.     With Selection
  10.         .Copy
  11.         With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, Selection.Height).Chart
  12.             .Paste
  13.             .Export Desktop & "" & VBA.Replace(VBA.Replace(Rng.Address, ":", "-"), "$", "") & ".jpg"
  14.             .Parent.Delete
  15.         End With
  16.         .Delete
  17.     End With
  18. '    Shell "explorer.exe " & Desktop, vbMaximizedFocus  '打开文件夹
  19. End Sub
复制代码

n.zip

18.47 KB, 下载次数: 2

回复

使用道具 举报

 楼主| 发表于 2015-5-23 12:42 | 显示全部楼层
本帖最后由 白云无尽9987 于 2015-5-23 14:01 编辑
xdragon 发表于 2015-5-23 12:33

②、③完美解决,①还没有做到————请问能以单元格A1里的内容为文件名吗?!~谢谢!
QQ拼音截图未命名.jpg
回复

使用道具 举报

发表于 2015-5-23 14:03 | 显示全部楼层    本楼为最佳答案   
  1. Sub main()
  2.     Dim Rng As Range, Desktop As String
  3.     If TypeName(Selection) <> "Range" Then MsgBox "必须选择单元格!", , "提示": Exit Sub
  4.     If Selection.Areas.Count > 1 Then MsgBox "只能选择一个区域!", , "提示": Exit Sub
  5.     Set Rng = Range("A2:B5")
  6.     Desktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
  7.     Rng.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
  8.     ActiveSheet.Pictures.Paste.Select
  9.     With Selection
  10.         .Copy
  11.         With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, Selection.Height).Chart
  12.             .Paste
  13.             .Export Desktop & "" & Range("A1") & ".jpg"
  14.             .Parent.Delete
  15.         End With
  16.         .Delete
  17.     End With
  18. '    Shell "explorer.exe " & Desktop, vbMaximizedFocus  '打开文件夹
  19. End Sub
复制代码

n.zip

18.35 KB, 下载次数: 4

评分

参与人数 1 +1 收起 理由
白云无尽9987 + 1 很给力!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2015-5-23 14:14 | 显示全部楼层
xdragon 发表于 2015-5-23 14:03

感激不尽!{:021:}
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-14 03:44 , Processed in 0.332516 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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