我有一些简单的代码试图将单个图像导出到文件夹。我将图像手动插入到工作簿中,并重命名了“徽标”形状。有谁知道为什么这段代码不起作用?我以前使用过类似的东西,但也许仅适用于OLEObjects?
ThisWorkbook.Sheets("Start Here").Shapes("logo").Copy
CreateObject("Shell.Application").Namespace(ThisWorkbook.Path & "\").Self.InvokeVerb "Paste"
编辑:为澄清起见,代码会运行,但是对象没有“粘贴”到目标目录。感谢您的帮助!
答案 0 :(得分:1)
Sub test()
Dim chtObj As ChartObject
With ThisWorkbook.Worksheets("Start Here")
.Activate
Set chtObj = .ChartObjects.Add(100, 30, 400, 250)
chtObj.Name = "TemporaryPictureChart"
'resize chart to picture size
chtObj.Width = .Shapes("logo").Width
chtObj.Height = .Shapes("logo").Height
ActiveSheet.Shapes.Range(Array("logo")).Select
Selection.Copy
ActiveSheet.ChartObjects("TemporaryPictureChart").Activate
ActiveChart.Paste
ActiveChart.Export Filename:=ThisWorkbook.Path & "\image.jpg", FilterName:="jpg"
chtObj.Delete
End With
End Sub
的更新代码