[英]Excel Save range as jpg
I have a workbook where I create printouts for a sort of to-do list.我有一本工作簿,可以在其中为待办事项列表创建打印输出。 Each to-do list is the same number of cells/size.每个待办事项列表都是相同数量的单元格/大小。 Instead of printing these lists, I want to export each list as a jpg file.我不想打印这些列表,而是想将每个列表导出为 jpg 文件。 I found this thread: VBA - Range to jpg picture which got me started but I am unsure on how to set the filename as a combination of 2 cells within the selected range.我找到了这个线程: VBA - Range to jpg 图片这让我开始了,但我不确定如何将文件名设置为所选范围内 2 个单元格的组合。
Range is always 6x23 cells范围始终为 6x23 单元格
Example range 1: B2:G24
Filename should be = F2
& C24
& ".jgp"
示例范围 1: B2:G24
文件名应为 = F2
& C24
& ".jgp"
Example range 2: J27:O49
Filename should be = N27
& K49
& ".jgp"
示例范围 2: J27:O49
文件名应为 = N27
& K49
& ".jgp"
This code exports the selected range as Case.jpg
此代码将所选范围导出为Case.jpg
Sub Export()
Dim oWs As Worksheet
Dim oRng As Range
Dim oChrtO As ChartObject
Dim lWidth As Long, lHeight As Long
Set oWs = ActiveSheet
Set oRng = Selection
oRng.CopyPicture xlScreen, xlPicture
lWidth = oRng.Width
lHeight = oRng.Height
Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
oChrtO.Activate
With oChrtO.Chart
.Paste
.Export Filename:="Case.jpg", Filtername:="JPG"
End With
oChrtO.Delete
End Sub
If oRng
is your selection then the first cell (F2 for Range1) would be oRng.Cells(1, 5)
and the other (C24 for Range1) would be oRng.Cells(23, 2)
如果oRng
是您的选择,那么第一个单元格(Range1 的 F2)将为oRng.Cells(1, 5)
,另一个(Range1 的 C24)将为oRng.Cells(23, 2)
So:所以:
.Export Filename:="C:\Test\" & oRng.Cells(1, 5).Value & "-" & _
oRng.Cells(23, 2).Value & ".jpg", Filtername:="JPG"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.