我正在尝试使用按钮截取范围的屏幕截图并将JPEG放在同一文件夹中。定义的范围是'header'
它运行良好一段时间然后突然间我得到以下错误之一。
Vba代码:
Sub CommandB_Click()
dt = Format(CStr(Now), "yy_mm_dd_hh_mm")
Const FName As String = "Screenshotzx.jpg"
Dim pic_rng As Range
Dim ShTemp As Worksheet
Dim ChTemp As Chart
Dim PicTemp As Picture
Application.ScreenUpdating = False
Set pic_rng = ActiveSheet.Range("header")
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChTemp.Paste
Set PicTemp = Selection
With ChTemp.Parent
.Width = 1400
.Height = 720
End With
ChTemp.Export Filename:=ThisWorkbook.Path & "\" & "Scrnsht.jpg", FilterName:="jpg"
Application.DisplayAlerts = False
ShTemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
错误代码13类型不匹配在以下行
Set PicTemp = Selection
以下行错误代码1004
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
答案 0 :(得分:0)
这样的事情(摆脱未使用的变量my_matrix
和dt
并避免Fname
,ActiveSheet
和ActiveChart
)?请注意,这使用Selection
,仅在Excel 2013及更高版本中可用。
AddChart2