vba 将图表从一个工作簿复制到另一个
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8764685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copying Chart from one Workbook to another
提问by Jorg Ancrath
I'm working on building a couple of report files for Excel, it basically copies information over to another Workbook and saves it.
我正在为 Excel 构建几个报告文件,它基本上将信息复制到另一个工作簿并保存。
I've managed to copy my textual content just fine, but now I need to be able to copy charts over, and this is when the errors start popping...
我已经成功地复制了我的文本内容,但现在我需要能够复制图表,这是错误开始出现的时候......
This is what I tried:
这是我尝试过的:
ActiveSheet.Shapes(1).CopyPicture Appearance:=xlScreen, Format:=xlPicture
Workbooks("Relatorios.xlsm").Sheets("" & tb_nome.Text & "").Paste
This seems to work fine, the only issue is that I want the chart placed on the cell E20, I tried selecting this cell but I get an error, this is what I tried:
这似乎工作正常,唯一的问题是我想要将图表放在单元格 E20 上,我尝试选择此单元格但出现错误,这是我尝试的:
Workbooks("Relatorios.xlsm").Sheets("" & tb_nome.Text & "").Range("E20").Select
Without that line the chart is pasted just fine, just not where I want it.
没有那条线,图表粘贴得很好,只是不是我想要的地方。
So the final code looked like:
所以最终的代码看起来像:
ActiveSheet.Shapes(1).CopyPicture Appearance:=xlScreen, Format:=xlPicture
Workbooks("Relatorios.xlsm").Sheets("" & tb_nome.Text & "").Range("E20").Select
Workbooks("Relatorios.xlsm").Sheets("" & tb_nome.Text & "").Paste
回答by Tim Williams
ActiveSheet.Shapes(1).CopyPicture Appearance:=xlScreen, Format:=xlPicture
With Workbooks("Relatorios.xlsm").Sheets(tb_nome.Text)
.Paste
.Shapes(.Shapes.Count).Top = .Range("E20").Top
.Shapes(.Shapes.Count).Left = .Range("E20").Left
End With