【发布时间】:2015-12-03 09:29:39
【问题描述】:
我尝试使用 VBA 代码在 Excel 中截取工作表的屏幕截图,然后将其保存在指定路径中,但我无法正确保存它...
Sub My_Macro(Test, Path)
Dim sSheetName As String
Dim oRangeToCopy As Range
Dim FirstCell As Range, LastCell As Range
Worksheets(Test).Activate
Set LastCell = Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column)
Set FirstCell = Cells(Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlRows, _
SearchDirection:=xlNext, LookIn:=xlValues).Row, _
Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, LookIn:=xlValues).Column)
sSheetName = Test ' worksheet to work on
With Worksheets(sSheetName)
.Range(FirstCell, LastCell).CopyPicture xlScreen, xlPicture
.Export Filename:=Path + Test + ".jpg", Filtername:="JPG"
End With
End Sub
Excel 不想在截屏后直接执行 .Export... 方法。 所以我尝试将图片粘贴到新图表中。 Excel 将图表图片保存在正确的位置,并在我的图片上添加图表...我也尝试将其粘贴到临时工作表中,但 Excel 不想将其导出...
任何想法
【问题讨论】:
-
我不认为 jpg 是 Excel 的有效导出格式(当您尝试手动导出 Excel 工作表时,请参阅列表)所以当您强制它这样做时,Excel 不知道该怎么做在代码中。