如何实现vba将excel图表转存为jpg格式?
需要选定a1到d3的区域复制,然后打开windows画图粘贴后保存为jpgRange("A1:D12").SelectSelection.CopyShell"C:\WIN...
需要选定a1到d3的区域复制,然后打开windows画图粘贴后保存为jpg
Range("A1:D12").Select
Selection.Copy
Shell "C:\WINDOWS\system32\mspaint.exe ", 1
只到这步就不会了…… 展开
Range("A1:D12").Select
Selection.Copy
Shell "C:\WINDOWS\system32\mspaint.exe ", 1
只到这步就不会了…… 展开
2个回答
展开全部
不需要打开画图板,用VBA代码就可以实现。
Sub test()
Dim myPic As Shape, pic As Shape
Dim rng As Range
n = ActiveSheet.Shapes.Count
Set rng = Application.InputBox("请选择需要截取的屏幕范围:", "截取范围", Type:=8)
rng.CopyPicture xlScreen, xlBitmap
ActiveSheet.Paste Destination:=ActiveSheet.Range("A1")
Set myPic = ActiveSheet.Shapes(n + 1)
With ActiveSheet.ChartObjects.Add(0, 0, myPic.Width, myPic.Height).Chart
myPic.Copy
.Paste
SaveName = Application.GetSaveAsFilename(InitialFileName:="MyExcelPic", filefilter:="图片文件(*.JPG),*.JPG")
If SaveName <> "False" Then .Export SaveName, "JPG"
.Parent.Delete
End With
myPic.Delete
Set myPic = Nothing
Set rng = Nothing
End Sub
Sub test()
Dim myPic As Shape, pic As Shape
Dim rng As Range
n = ActiveSheet.Shapes.Count
Set rng = Application.InputBox("请选择需要截取的屏幕范围:", "截取范围", Type:=8)
rng.CopyPicture xlScreen, xlBitmap
ActiveSheet.Paste Destination:=ActiveSheet.Range("A1")
Set myPic = ActiveSheet.Shapes(n + 1)
With ActiveSheet.ChartObjects.Add(0, 0, myPic.Width, myPic.Height).Chart
myPic.Copy
.Paste
SaveName = Application.GetSaveAsFilename(InitialFileName:="MyExcelPic", filefilter:="图片文件(*.JPG),*.JPG")
If SaveName <> "False" Then .Export SaveName, "JPG"
.Parent.Delete
End With
myPic.Delete
Set myPic = Nothing
Set rng = Nothing
End Sub
追问
您好,谢谢您的回答,还想请问您,要是有要求必须调用画图软件,并把复制的内容贴进去并保存,可以实现么?万分感谢了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |